mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	More style tweaks
This commit is contained in:
		| @@ -62,12 +62,12 @@ void AntimagicMechanics::applyBattle(BattleInfo * battle, const BattleSpellCast | ||||
| } | ||||
|  | ||||
| ///ChainLightningMechanics | ||||
| std::set<const CStack *> ChainLightningMechanics::getAffectedStacks(SpellTargetingContext & ctx) const | ||||
| std::set<const CStack *> ChainLightningMechanics::getAffectedStacks(const CBattleInfoCallback * cb, SpellTargetingContext & ctx) const | ||||
| { | ||||
| 	std::set<const CStack* > attackedCres; | ||||
|  | ||||
| 	std::set<BattleHex> possibleHexes; | ||||
| 	for(auto stack : ctx.cb->battleGetAllStacks()) | ||||
| 	for(auto stack : cb->battleGetAllStacks()) | ||||
| 	{ | ||||
| 		if(stack->isValidTarget()) | ||||
| 		{ | ||||
| @@ -82,7 +82,7 @@ std::set<const CStack *> ChainLightningMechanics::getAffectedStacks(SpellTargeti | ||||
| 	BattleHex lightningHex = ctx.destination; | ||||
| 	for(int i = 0; i < targetsOnLevel[ctx.schoolLvl]; ++i) | ||||
| 	{ | ||||
| 		auto stack = ctx.cb->battleGetStackByPos(lightningHex, true); | ||||
| 		auto stack = cb->battleGetStackByPos(lightningHex, true); | ||||
| 		if(!stack) | ||||
| 			break; | ||||
| 		attackedCres.insert (stack); | ||||
| @@ -378,11 +378,11 @@ ESpellCastProblem::ESpellCastProblem HypnotizeMechanics::isImmuneByStack(const I | ||||
| } | ||||
|  | ||||
| ///ObstacleMechanics | ||||
| ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const SpellTargetingContext & ctx) const | ||||
| ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const | ||||
| { | ||||
| 	if(ctx.ti.clearAffected) | ||||
| 	{ | ||||
| 		ui8 side = ctx.cb->playerToSide(ctx.caster->getOwner()); | ||||
| 		ui8 side = cb->playerToSide(ctx.caster->getOwner()); | ||||
|  | ||||
| 		bool hexesOutsideBattlefield = false; | ||||
|  | ||||
| @@ -390,7 +390,7 @@ ESpellCastProblem::ESpellCastProblem ObstacleMechanics::canBeCast(const SpellTar | ||||
|  | ||||
| 		for(BattleHex hex : tilesThatMustBeClear) | ||||
| 		{ | ||||
| 			if(ctx.cb->battleGetStackByPos(hex, true) || !!ctx.cb->battleGetObstacleOnPos(hex, false) || !hex.isAvailable()) | ||||
| 			if(cb->battleGetStackByPos(hex, true) || !!cb->battleGetObstacleOnPos(hex, false) || !hex.isAvailable()) | ||||
| 			{ | ||||
| 				return ESpellCastProblem::NO_APPROPRIATE_TARGET; | ||||
| 			} | ||||
| @@ -572,9 +572,9 @@ ESpellCastProblem::ESpellCastProblem RemoveObstacleMechanics::canBeCast(const CB | ||||
| 	return ESpellCastProblem::NO_APPROPRIATE_TARGET; | ||||
| } | ||||
|  | ||||
| ESpellCastProblem::ESpellCastProblem RemoveObstacleMechanics::canBeCast(const SpellTargetingContext & ctx) const | ||||
| ESpellCastProblem::ESpellCastProblem RemoveObstacleMechanics::canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const | ||||
| { | ||||
| 	if(auto obstacle = ctx.cb->battleGetObstacleOnPos(ctx.destination, false)) | ||||
| 	if(auto obstacle = cb->battleGetObstacleOnPos(ctx.destination, false)) | ||||
| 		if(canRemove(obstacle.get(), ctx.schoolLvl)) | ||||
| 			return ESpellCastProblem::OK; | ||||
|  | ||||
| @@ -701,9 +701,9 @@ int SacrificeMechanics::calculateHealedHP(const SpellCastEnvironment* env, const | ||||
| } | ||||
|  | ||||
| ///SpecialRisingSpellMechanics | ||||
| ESpellCastProblem::ESpellCastProblem SpecialRisingSpellMechanics::canBeCast(const SpellTargetingContext & ctx) const | ||||
| ESpellCastProblem::ESpellCastProblem SpecialRisingSpellMechanics::canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const | ||||
| { | ||||
| 	const CStack * stack = ctx.cb->getStackIf([ctx](const CStack * s) | ||||
| 	const CStack * stack = cb->getStackIf([ctx](const CStack * s) | ||||
| 	{ | ||||
| 		const bool ownerMatches = !ctx.ti.smart || s->getOwner() == ctx.caster->getOwner(); | ||||
|  | ||||
|   | ||||
| @@ -43,7 +43,7 @@ class DLL_LINKAGE ChainLightningMechanics : public DefaultSpellMechanics | ||||
| { | ||||
| public: | ||||
| 	ChainLightningMechanics(CSpell * s): DefaultSpellMechanics(s){}; | ||||
| 	std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const override; | ||||
| 	std::set<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, SpellTargetingContext & ctx) const override; | ||||
| }; | ||||
|  | ||||
| class DLL_LINKAGE CloneMechanics : public DefaultSpellMechanics | ||||
| @@ -96,7 +96,7 @@ class DLL_LINKAGE ObstacleMechanics : public DefaultSpellMechanics | ||||
| { | ||||
| public: | ||||
| 	ObstacleMechanics(CSpell * s): DefaultSpellMechanics(s){}; | ||||
| 	ESpellCastProblem::ESpellCastProblem canBeCast(const SpellTargetingContext & ctx) const override; | ||||
| 	ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override; | ||||
| protected: | ||||
| 	void applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override; | ||||
| }; | ||||
| @@ -113,7 +113,7 @@ class DLL_LINKAGE RemoveObstacleMechanics : public DefaultSpellMechanics | ||||
| public: | ||||
| 	RemoveObstacleMechanics(CSpell * s): DefaultSpellMechanics(s){}; | ||||
| 	ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const override; | ||||
| 	ESpellCastProblem::ESpellCastProblem canBeCast(const SpellTargetingContext & ctx) const override; | ||||
| 	ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override; | ||||
| protected: | ||||
| 	void applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const override; | ||||
| private: | ||||
| @@ -145,7 +145,7 @@ class DLL_LINKAGE SpecialRisingSpellMechanics : public RisingSpellMechanics | ||||
| { | ||||
| public: | ||||
| 	SpecialRisingSpellMechanics(CSpell * s): RisingSpellMechanics(s){}; | ||||
| 	ESpellCastProblem::ESpellCastProblem canBeCast(const SpellTargetingContext & ctx) const override; | ||||
| 	ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override; | ||||
| 	ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const override; | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -668,11 +668,11 @@ std::vector<BattleHex> DefaultSpellMechanics::rangeInHexes(BattleHex centralHex, | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(SpellTargetingContext & ctx) const | ||||
| std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(const CBattleInfoCallback * cb, SpellTargetingContext & ctx) const | ||||
| { | ||||
| 	std::set<const CStack* > attackedCres;//std::set to exclude multiple occurrences of two hex creatures | ||||
|  | ||||
| 	const ui8 attackerSide = ctx.cb->playerToSide(ctx.caster->getOwner()) == 1; | ||||
| 	const ui8 attackerSide = cb->playerToSide(ctx.caster->getOwner()) == 1; | ||||
| 	const auto attackedHexes = rangeInHexes(ctx.destination, ctx.schoolLvl, attackerSide); | ||||
|  | ||||
| 	//TODO: more generic solution for mass spells | ||||
| @@ -680,7 +680,7 @@ std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(SpellTargeting | ||||
| 	{ | ||||
| 		for(BattleHex hex : attackedHexes) | ||||
| 		{ | ||||
| 			if(const CStack * st = ctx.cb->battleGetStackByPos(hex, ctx.ti.onlyAlive)) | ||||
| 			if(const CStack * st = cb->battleGetStackByPos(hex, ctx.ti.onlyAlive)) | ||||
| 			{ | ||||
| 				attackedCres.insert(st); | ||||
| 			} | ||||
| @@ -701,7 +701,7 @@ std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(SpellTargeting | ||||
| 			return rangeCovers && positivenessFlag && validTarget; | ||||
| 		}; | ||||
|  | ||||
| 		TStacks stacks = ctx.cb->battleGetStacksIf(predicate); | ||||
| 		TStacks stacks = cb->battleGetStacksIf(predicate); | ||||
|  | ||||
| 		if(ctx.ti.massive) | ||||
| 		{ | ||||
| @@ -731,7 +731,7 @@ std::set<const CStack *> DefaultSpellMechanics::getAffectedStacks(SpellTargeting | ||||
| 	{ | ||||
| 		for(BattleHex hex : attackedHexes) | ||||
| 		{ | ||||
| 			if(const CStack * st = ctx.cb->battleGetStackByPos(hex, ctx.ti.onlyAlive)) | ||||
| 			if(const CStack * st = cb->battleGetStackByPos(hex, ctx.ti.onlyAlive)) | ||||
| 				attackedCres.insert(st); | ||||
| 		} | ||||
| 	} | ||||
| @@ -745,7 +745,7 @@ ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCast(const CBat | ||||
| 	return ESpellCastProblem::OK; | ||||
| } | ||||
|  | ||||
| ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCast(const SpellTargetingContext & ctx) const | ||||
| ESpellCastProblem::ESpellCastProblem DefaultSpellMechanics::canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const | ||||
| { | ||||
| 	//no problems by default, this method is for spell-specific problems | ||||
| 	//common problems handled by CSpell | ||||
|   | ||||
| @@ -38,10 +38,10 @@ public: | ||||
| 	DefaultSpellMechanics(CSpell * s): ISpellMechanics(s){}; | ||||
|  | ||||
| 	std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const override; | ||||
| 	std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const override; | ||||
| 	std::set<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, 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 canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const override; | ||||
|  | ||||
| 	ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const override; | ||||
|  | ||||
|   | ||||
| @@ -155,9 +155,9 @@ std::vector<BattleHex> CSpell::rangeInHexes(BattleHex centralHex, ui8 schoolLvl, | ||||
|  | ||||
| std::set<const CStack *> CSpell::getAffectedStacks(const CBattleInfoCallback * cb, ECastingMode::ECastingMode mode, const ISpellCaster * caster, int spellLvl, BattleHex destination) const | ||||
| { | ||||
| 	ISpellMechanics::SpellTargetingContext ctx(this, cb, mode, caster, spellLvl, destination); | ||||
| 	SpellTargetingContext ctx(this, mode, caster, spellLvl, destination); | ||||
|  | ||||
| 	std::set<const CStack* > attackedCres = mechanics->getAffectedStacks(ctx); | ||||
| 	std::set<const CStack* > attackedCres = mechanics->getAffectedStacks(cb, ctx); | ||||
|  | ||||
| 	//now handle immunities | ||||
| 	auto predicate = [&, this](const CStack * s)->bool | ||||
| @@ -302,9 +302,9 @@ 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 | ||||
| { | ||||
| 	ISpellMechanics::SpellTargetingContext ctx(this, cb, mode, caster, caster->getSpellSchoolLevel(this), destination); | ||||
| 	SpellTargetingContext ctx(this, mode, caster, caster->getSpellSchoolLevel(this), destination); | ||||
|  | ||||
| 	ESpellCastProblem::ESpellCastProblem specific = mechanics->canBeCast(ctx); | ||||
| 	ESpellCastProblem::ESpellCastProblem specific = mechanics->canBeCast(cb, ctx); | ||||
|  | ||||
| 	if(specific != ESpellCastProblem::OK) | ||||
| 		return specific; | ||||
|   | ||||
| @@ -82,33 +82,32 @@ struct DLL_LINKAGE AdventureSpellCastParameters | ||||
| 	int3 pos; | ||||
| }; | ||||
|  | ||||
| struct DLL_LINKAGE SpellTargetingContext | ||||
| { | ||||
| 	CSpell::TargetInfo ti; | ||||
| 	ECastingMode::ECastingMode mode; | ||||
| 	BattleHex destination; | ||||
| 	const ISpellCaster * caster; | ||||
| 	int schoolLvl; | ||||
|  | ||||
| 	SpellTargetingContext(const CSpell * s, ECastingMode::ECastingMode mode_, const ISpellCaster * caster_, int schoolLvl_, BattleHex destination_) | ||||
| 		: ti(s,schoolLvl_, mode_), mode(mode_), destination(destination_), caster(caster_), schoolLvl(schoolLvl_) | ||||
| 	{}; | ||||
|  | ||||
| }; | ||||
|  | ||||
| class DLL_LINKAGE ISpellMechanics | ||||
| { | ||||
| public: | ||||
| 	struct DLL_LINKAGE SpellTargetingContext | ||||
| 	{ | ||||
| 		const CBattleInfoCallback * cb; | ||||
| 		CSpell::TargetInfo ti; | ||||
| 		ECastingMode::ECastingMode mode; | ||||
| 		BattleHex destination; | ||||
| 		const ISpellCaster * caster; | ||||
| 		int schoolLvl; | ||||
|  | ||||
| 		SpellTargetingContext(const CSpell * s, const CBattleInfoCallback * c, ECastingMode::ECastingMode mode_, const ISpellCaster * caster_, int schoolLvl_, BattleHex destination_) | ||||
| 			: cb(c), ti(s,schoolLvl_, mode_), mode(mode_), destination(destination_), caster(caster_), schoolLvl(schoolLvl_) | ||||
| 		{}; | ||||
|  | ||||
| 	}; | ||||
| public: | ||||
| 	ISpellMechanics(CSpell * s); | ||||
| 	virtual ~ISpellMechanics(){}; | ||||
|  | ||||
| 	virtual std::vector<BattleHex> rangeInHexes(BattleHex centralHex, ui8 schoolLvl, ui8 side, bool * outDroppedHexes = nullptr) const = 0; | ||||
| 	virtual std::set<const CStack *> getAffectedStacks(SpellTargetingContext & ctx) const = 0; | ||||
| 	virtual std::set<const CStack *> getAffectedStacks(const CBattleInfoCallback * cb, SpellTargetingContext & ctx) const = 0; | ||||
|  | ||||
| 	virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const ISpellCaster * caster) const = 0; | ||||
|  | ||||
| 	virtual ESpellCastProblem::ESpellCastProblem canBeCast(const SpellTargetingContext & ctx) const = 0; | ||||
| 	virtual ESpellCastProblem::ESpellCastProblem canBeCast(const CBattleInfoCallback * cb, const SpellTargetingContext & ctx) const = 0; | ||||
|  | ||||
| 	virtual ESpellCastProblem::ESpellCastProblem isImmuneByStack(const ISpellCaster * caster, const CStack * obj) const = 0; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user