mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Spell cast logging refactored.
This commit is contained in:
		| @@ -1249,6 +1249,14 @@ void CStack::getCasterName(MetaString & text) const | ||||
| 	text.addReplacement(MetaString::CRE_PL_NAMES, type->idNumber.num); | ||||
| } | ||||
|  | ||||
| void CStack::getCastDescription(const CSpell * spell, const std::vector<const CStack*> & attacked, MetaString & text) const | ||||
| { | ||||
| 	text.addTxt(MetaString::GENERAL_TXT, 565);//The %s casts %s | ||||
| 	//todo: use text 566 for single creature | ||||
| 	getCasterName(text); | ||||
| 	text.addReplacement(MetaString::SPELL_NAME, spell->id.toEnum()); | ||||
| } | ||||
|  | ||||
| bool CMP_stack::operator()( const CStack* a, const CStack* b ) | ||||
| { | ||||
| 	switch(phase) | ||||
|   | ||||
| @@ -251,6 +251,8 @@ public: | ||||
|  | ||||
| 	void getCasterName(MetaString & text) const override; | ||||
|  | ||||
| 	void getCastDescription(const CSpell * spell, const std::vector<const CStack *> & attacked, MetaString & text) const override; | ||||
|  | ||||
| 	///stack will be ghost in next battle state update | ||||
| 	void makeGhost(); | ||||
|  | ||||
|   | ||||
| @@ -960,6 +960,18 @@ void CGHeroInstance::getCasterName(MetaString & text) const | ||||
|     text.addReplacement(name); | ||||
| } | ||||
|  | ||||
| void CGHeroInstance::getCastDescription(const CSpell * spell, const std::vector<const CStack*> & attacked, MetaString & text) const | ||||
| { | ||||
| 	const bool singleTarget = attacked.size() == 1; | ||||
| 	const int textIndex = singleTarget ? 195 : 196; | ||||
|  | ||||
| 	text.addTxt(MetaString::GENERAL_TXT, textIndex); | ||||
| 	getCasterName(text); | ||||
| 	text.addReplacement(MetaString::SPELL_NAME, spell->id.toEnum()); | ||||
| 	if(singleTarget) | ||||
| 		text.addReplacement(MetaString::CRE_PL_NAMES, attacked.at(0)->getCreature()->idNumber.num); | ||||
| } | ||||
|  | ||||
| bool CGHeroInstance::canCastThisSpell(const CSpell * spell) const | ||||
| { | ||||
| 	if(nullptr == getArt(ArtifactPosition::SPELLBOOK)) | ||||
|   | ||||
| @@ -247,6 +247,7 @@ public: | ||||
| 	const PlayerColor getOwner() const override; | ||||
|  | ||||
| 	void getCasterName(MetaString & text) const override; | ||||
| 	void getCastDescription(const CSpell * spell, const std::vector<const CStack *> & attacked, MetaString & text) const override; | ||||
|  | ||||
| 	void deserializationFix(); | ||||
|  | ||||
|   | ||||
| @@ -155,40 +155,9 @@ void SpellCastContext::setDamageToDisplay(const si32 value) | ||||
|  | ||||
| void SpellCastContext::prepareBattleLog() | ||||
| { | ||||
| 	//todo: prepare battle log | ||||
| 	bool displayDamage = true; | ||||
|  | ||||
| 	if(attackedCres.size() == 1) | ||||
| 	{ | ||||
| 		const CStack * attackedStack = *attackedCres.begin(); | ||||
|  | ||||
| 		switch(parameters.mode) | ||||
| 		{ | ||||
| 		case ECastingMode::HERO_CASTING: | ||||
| 			{ | ||||
| 				MetaString line; | ||||
| 				line.addTxt(MetaString::GENERAL_TXT, 195); | ||||
| 				parameters.caster->getCasterName(line); | ||||
| 				line.addReplacement(MetaString::SPELL_NAME, mechanics->owner->id.toEnum()); | ||||
| 				line.addReplacement(MetaString::CRE_PL_NAMES, attackedStack->getCreature()->idNumber.num); | ||||
| 			} | ||||
| 			break; | ||||
|  | ||||
| 		default: | ||||
| 			{ | ||||
| 				mechanics->battleLogSingleTarget(sc.battleLog, parameters, attackedStack, damageToDisplay, displayDamage); | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		MetaString line; | ||||
| 		line.addTxt(MetaString::GENERAL_TXT, 196); | ||||
|         parameters.caster->getCasterName(line); | ||||
| 		line.addReplacement(MetaString::SPELL_NAME, mechanics->owner->id.toEnum()); | ||||
| 		sc.battleLog.push_back(line); | ||||
| 	} | ||||
| 	mechanics->battleLog(sc.battleLog, parameters, attackedCres, damageToDisplay, displayDamage); | ||||
|  | ||||
| 	displayDamage = displayDamage && damageToDisplay > 0; | ||||
|  | ||||
| @@ -359,9 +328,18 @@ void DefaultSpellMechanics::cast(const SpellCastEnvironment * env, const BattleS | ||||
| 	ctx.afterCast(); | ||||
| } | ||||
|  | ||||
| void DefaultSpellMechanics::battleLogSingleTarget(std::vector<MetaString>&  logLines, const BattleSpellCastParameters & parameters, | ||||
| 	const CStack * attackedStack, const si32 damageToDisplay, bool & displayDamage) const | ||||
| void DefaultSpellMechanics::battleLog(std::vector<MetaString> & logLines, const BattleSpellCastParameters & parameters, | ||||
| 	const std::vector<const CStack *> & attacked, const si32 damageToDisplay, bool & displayDamage) const | ||||
| { | ||||
| 	if(attacked.size() != 1) | ||||
| 	{ | ||||
| 		displayDamage = true; | ||||
| 		battleLogDefault(logLines, parameters, attacked); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	auto attackedStack = attacked.at(0); | ||||
|  | ||||
| 	auto getPluralFormat = [attackedStack](const int baseTextID) -> si32 | ||||
| 	{ | ||||
| 		return attackedStack->count > 1 ? baseTextID + 1 : baseTextID; | ||||
| @@ -451,19 +429,19 @@ void DefaultSpellMechanics::battleLogSingleTarget(std::vector<MetaString>&  logL | ||||
| 		} | ||||
| 		break; | ||||
| 	default: | ||||
| 		{ | ||||
| 			MetaString line; | ||||
| 			line.addTxt(MetaString::GENERAL_TXT, 565);//The %s casts %s | ||||
| 			//todo: use text 566 for single creature | ||||
| 			parameters.caster->getCasterName(line); | ||||
| 			line.addReplacement(MetaString::SPELL_NAME, owner->id.toEnum()); | ||||
| 			displayDamage = true; | ||||
| 			logLines.push_back(line); | ||||
| 		} | ||||
| 		displayDamage = true; | ||||
| 		battleLogDefault(logLines, parameters, attacked); | ||||
| 		break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void DefaultSpellMechanics::battleLogDefault(std::vector<MetaString> & logLines, const BattleSpellCastParameters & parameters, const std::vector<const CStack*> & attacked) const | ||||
| { | ||||
| 	MetaString line; | ||||
| 	parameters.caster->getCastDescription(owner, attacked, line); | ||||
| 	logLines.push_back(line); | ||||
| } | ||||
|  | ||||
| void DefaultSpellMechanics::applyBattleEffects(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters, SpellCastContext & ctx) const | ||||
| { | ||||
| 	//applying effects | ||||
|   | ||||
| @@ -59,8 +59,11 @@ public: | ||||
|  | ||||
| 	void battleCast(const SpellCastEnvironment * env, const BattleSpellCastParameters & parameters) const override final; | ||||
|  | ||||
| 	void battleLogSingleTarget(std::vector<MetaString> & logLines, const BattleSpellCastParameters & parameters, | ||||
| 		const CStack * attackedStack, const si32 damageToDisplay, bool & displayDamage) const; | ||||
| 	void battleLog(std::vector<MetaString> & logLines, const BattleSpellCastParameters & parameters, | ||||
| 		const std::vector<const CStack *> & attacked, const si32 damageToDisplay, bool & displayDamage) const; | ||||
|  | ||||
| 	void battleLogDefault(std::vector<MetaString> & logLines, const BattleSpellCastParameters & parameters, | ||||
| 		const std::vector<const CStack *> & attacked) const; | ||||
|  | ||||
| 	bool requiresCreatureTarget() const	override; | ||||
| protected: | ||||
|   | ||||
| @@ -47,5 +47,9 @@ public: | ||||
|  | ||||
| 	virtual const PlayerColor getOwner() const = 0; | ||||
|  | ||||
| 	///only name substitution | ||||
| 	virtual void getCasterName(MetaString & text) const = 0; | ||||
|  | ||||
| 	///full default text | ||||
| 	virtual void getCastDescription(const CSpell * spell, const std::vector<const CStack *> & attacked, MetaString & text) const = 0; | ||||
| }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user