瀏覽代碼

vcmi: allow obstacles to store another spells

It will be used as trigger spell, if set
If not set, it will be ignored
Konstantin 2 年之前
父節點
當前提交
db428faeeb

+ 3 - 1
lib/battle/CObstacleInstance.cpp

@@ -98,7 +98,8 @@ SpellCreatedObstacle::SpellCreatedObstacle()
 	removeOnTrigger(false),
 	revealed(false),
 	animationYOffset(0),
-	nativeVisible(true)
+	nativeVisible(true),
+	minimalDamage(0)
 {
 	obstacleType = SPELL_CREATED;
 }
@@ -160,6 +161,7 @@ void SpellCreatedObstacle::serializeJson(JsonSerializeFormat & handler)
 	handler.serializeInt("casterSpellPower", casterSpellPower);
 	handler.serializeInt("spellLevel", spellLevel);
 	handler.serializeInt("casterSide", casterSide);
+	handler.serializeInt("minimalDamage", minimalDamage);
 
 	handler.serializeBool("hidden", hidden);
 	handler.serializeBool("revealed", revealed);

+ 2 - 0
lib/battle/CObstacleInstance.h

@@ -68,6 +68,7 @@ struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
 	int32_t turnsRemaining;
 	int32_t casterSpellPower;
 	int32_t spellLevel;
+	int32_t minimalDamage; //How many damage should it do regardless of power and level of caster
 	si8 casterSide; //0 - obstacle created by attacker; 1 - by defender
 
 	bool hidden;
@@ -119,6 +120,7 @@ struct DLL_LINKAGE SpellCreatedObstacle : CObstacleInstance
 		h & nativeVisible;
 		h & passable;
 		h & trigger;
+		h & minimalDamage;
 		h & trap;
 
 		h & customSize;

+ 4 - 1
lib/spells/effects/Moat.cpp

@@ -39,6 +39,8 @@ void Moat::serializeJsonEffect(JsonSerializeFormat & handler)
 	handler.serializeBool("trap", trap);
 	handler.serializeBool("removeOnTrigger", removeOnTrigger);
 	handler.serializeBool("dispellable", dispellable);
+	handler.serializeInt("moatDamage", moatDamage);
+	handler.serializeId("triggerAbility", triggerAbility, SpellID::NONE);
 	{
 		JsonArraySerializer customSizeJson = handler.enterArray("moatHexes");
 		customSizeJson.syncSize(moatHexes, JsonNode::JsonType::DATA_INTEGER);
@@ -85,12 +87,13 @@ void Moat::placeObstacles(ServerCallback * server, const Mechanics * m, const Ef
 		obstacle.uniqueID = obstacleIdToGive++;
 		obstacle.pos = destination.hexValue;
 		obstacle.obstacleType = dispellable ? CObstacleInstance::SPELL_CREATED : CObstacleInstance::MOAT;
-		obstacle.ID = m->battle()->battleGetDefendedTown()->subID;
+		obstacle.ID = triggerAbility;
 
 		obstacle.turnsRemaining = -1; //Moat cannot be expired
 		obstacle.casterSpellPower = m->getEffectPower();
 		obstacle.spellLevel = m->getEffectLevel(); //todo: level of indirect effect should be also configurable
 		obstacle.casterSide = BattleSide::DEFENDER; // Moats are always cast by defender
+		obstacle.minimalDamage = moatDamage; // Minimal moat damage
 		obstacle.hidden = hidden;
 		obstacle.passable = true; //Moats always passable
 		obstacle.trigger = trigger;

+ 1 - 0
lib/spells/effects/Moat.h

@@ -25,6 +25,7 @@ private:
 	ObstacleSideOptions sideOptions; //Defender only
 	std::vector<BattleHex> moatHexes;
 	bool dispellable; //For Tower landmines
+	int moatDamage; // Minimal moat damage
 public:
 	void apply(ServerCallback * server, const Mechanics * m, const EffectTarget & target) const override;
 protected:

+ 3 - 2
lib/spells/effects/Obstacle.cpp

@@ -221,6 +221,7 @@ void Obstacle::serializeJsonEffect(JsonSerializeFormat & handler)
 
 	handler.serializeInt("patchCount", patchCount);
 	handler.serializeInt("turnsRemaining", turnsRemaining, -1);
+	handler.serializeId("triggerAbility", triggerAbility, SpellID::NONE);
 
 	handler.serializeStruct("attacker", sideOptions.at(BattleSide::ATTACKER));
 	handler.serializeStruct("defender", sideOptions.at(BattleSide::DEFENDER));
@@ -289,8 +290,8 @@ void Obstacle::placeObstacles(ServerCallback * server, const Mechanics * m, cons
 		SpellCreatedObstacle obstacle;
 		obstacle.uniqueID = obstacleIdToGive++;
 		obstacle.pos = destination.hexValue;
-		obstacle.obstacleType = CObstacleInstance::USUAL;
-		obstacle.ID = m->getSpellIndex();
+		obstacle.obstacleType = CObstacleInstance::SPELL_CREATED;
+		obstacle.ID = triggerAbility;
 
 		obstacle.turnsRemaining = turnsRemaining;
 		obstacle.casterSpellPower = m->getEffectPower();

+ 2 - 0
lib/spells/effects/Obstacle.h

@@ -11,6 +11,7 @@
 #pragma once
 
 #include "LocationEffect.h"
+#include "../../GameConstants.h"
 #include "../../battle/BattleHex.h"
 #include "../../battle/CObstacleInstance.h"
 
@@ -62,6 +63,7 @@ protected:
 	bool trap = false;
 	bool removeOnTrigger = false;
 	bool hideNative = false;
+	SpellID triggerAbility;
 private:
 	int32_t patchCount = 0; //random patches to place, for massive spells should be >= 1, for non-massive ones if >= 1, then place only this number inside a target (like H5 landMine)
 	int32_t turnsRemaining = -1;