Browse Source

Summon effect fixes.

AlexVinS 7 years ago
parent
commit
5ea1888a14
3 changed files with 15 additions and 9 deletions
  1. 4 3
      lib/spells/effects/Summon.cpp
  2. 1 0
      lib/spells/effects/Summon.h
  3. 10 6
      test/spells/effects/SummonTest.cpp

+ 4 - 3
lib/spells/effects/Summon.cpp

@@ -37,7 +37,8 @@ Summon::Summon()
 	creature(),
 	permanent(false),
 	exclusive(true),
-	summonByHealth(false)
+	summonByHealth(false),
+	summonSameUnit(false)
 {
 }
 
@@ -162,6 +163,7 @@ void Summon::serializeJsonEffect(JsonSerializeFormat & handler)
 	handler.serializeBool("permanent", permanent, false);
 	handler.serializeBool("exclusive", exclusive, true);
 	handler.serializeBool("summonByHealth", summonByHealth, false);
+	handler.serializeBool("summonSameUnit", summonSameUnit, false);
 }
 
 EffectTarget Summon::transformTarget(const Mechanics * m, const Target & aimPoint, const Target & spellTarget) const
@@ -177,7 +179,7 @@ EffectTarget Summon::transformTarget(const Mechanics * m, const Target & aimPoin
 
 	EffectTarget effectTarget;
 
-	if(sameSummoned.empty())
+	if(sameSummoned.empty() || !summonSameUnit)
 	{
 		BattleHex hex = m->cb->getAvaliableHex(creature, m->casterSide);
 		if(!hex.isValid())
@@ -193,6 +195,5 @@ EffectTarget Summon::transformTarget(const Mechanics * m, const Target & aimPoin
 	return effectTarget;
 }
 
-
 }
 }

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

@@ -44,6 +44,7 @@ private:
 	bool permanent;
 	bool exclusive;
 	bool summonByHealth;
+	bool summonSameUnit;
 };
 
 }

+ 10 - 6
test/spells/effects/SummonTest.cpp

@@ -24,12 +24,13 @@ using namespace ::testing;
 static const CreatureID creature1(CreatureID::AIR_ELEMENTAL);
 static const CreatureID creature2(CreatureID::FIRE_ELEMENTAL);
 
-class SummonTest : public TestWithParam<::testing::tuple<bool, CreatureID>>, public EffectFixture
+class SummonTest : public TestWithParam<::testing::tuple<CreatureID, bool, bool>>, public EffectFixture
 {
 public:
-	bool exclusive;
 	CreatureID toSummon;
 	CreatureID otherSummoned;
+	bool exclusive;
+	bool summonSameUnit;
 
 	const battle::Unit * otherSummonedUnit;
 
@@ -65,14 +66,16 @@ protected:
 	{
 		EffectFixture::setUp();
 
-		exclusive = ::testing::get<0>(GetParam());
-		otherSummoned = ::testing::get<1>(GetParam());
+		otherSummoned = ::testing::get<0>(GetParam());
+		exclusive = ::testing::get<1>(GetParam());
+		summonSameUnit = ::testing::get<2>(GetParam());
 
 		toSummon = creature1;
 
 		JsonNode options(JsonNode::JsonType::DATA_STRUCT);
 		options["id"].String() = "airElemental";
 		options["exclusive"].Bool() = exclusive;
+		options["summonSameUnit"].Bool() = summonSameUnit;
 
 		EffectFixture::setupEffect(options);
 	}
@@ -112,7 +115,7 @@ TEST_P(SummonTest, Transform)
 
 	EffectTarget expected;
 
-	if(otherSummoned == toSummon)
+	if(otherSummoned == toSummon && summonSameUnit)
 	{
 		expected.emplace_back(otherSummonedUnit);
 	}
@@ -130,8 +133,9 @@ INSTANTIATE_TEST_CASE_P
 	SummonTest,
 	Combine
 	(
+		Values(CreatureID(), creature1, creature2),
 		Values(false, true),
-		Values(CreatureID(), creature1, creature2)
+		Values(false, true)
 	)
 );