Browse Source

Merge pull request #4052 from vcmi/bank_battle

Config option for regular unit placement in Black Tower
Ivan Savenko 1 year ago
parent
commit
5c2ca380ab

+ 6 - 2
docs/modders/Map_Objects/Creature_Bank.md

@@ -3,6 +3,10 @@ Format of rewards is same as in [Rewardable Objects](Rewardable.md)
 
 ``` javascript
 {
+	/// If true, battle setup will be like normal - Attacking player on the left, enemy on the right
+	"regularUnitPlacement" : true,
+	/// If true, bank placed on water will be visitable from coast (Shipwreck)
+	"coastVisitable" : true,
 	/// List of levels of this bank. On map loading, one of them will be randomly assigned to bank.
 	"levels": [
 		{
@@ -52,9 +56,9 @@ Format of rewards is same as in [Rewardable Objects](Rewardable.md)
 
 				/// List of spells
 				"spells" : [ { "level" : 5 } ]
-				} 
-			}
+			} 
 		}
 	]
 }
+
 ```

+ 2 - 0
lib/mapObjectConstructors/CBankInstanceConstructor.cpp

@@ -33,6 +33,7 @@ void CBankInstanceConstructor::initTypeData(const JsonNode & input)
 	bankResetDuration = static_cast<si32>(input["resetDuration"].Float());
 	blockVisit = input["blockedVisitable"].Bool();
 	coastVisitable = input["coastVisitable"].Bool();
+	regularUnitPlacement = input["regularUnitPlacement"].Bool();
 }
 
 BankConfig CBankInstanceConstructor::generateConfig(IGameCallback * cb, const JsonNode & level, CRandomGenerator & rng) const
@@ -57,6 +58,7 @@ void CBankInstanceConstructor::randomizeObject(CBank * bank, CRandomGenerator &
 	bank->resetDuration = bankResetDuration;
 	bank->blockVisit = blockVisit;
 	bank->coastVisitable = coastVisitable;
+	bank->regularUnitPlacement = regularUnitPlacement;
 
 	si32 totalChance = 0;
 	for(const auto & node : levels)

+ 2 - 0
lib/mapObjectConstructors/CBankInstanceConstructor.h

@@ -79,6 +79,8 @@ class CBankInstanceConstructor : public CDefaultObjectTypeHandler<CBank>
 	bool blockVisit;
 	// bank is visitable from land even when bank is on water tile
 	bool coastVisitable;
+	//If true, player units will be placed on the left and enemy on the right
+	bool regularUnitPlacement;
 protected:
 	void initTypeData(const JsonNode & input) override;
 

+ 1 - 1
lib/mapObjects/CBank.cpp

@@ -398,7 +398,7 @@ void CBank::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer) cons
 	if (answer)
 	{
 		if (bankConfig) // not looted bank
-			cb->startBattleI(hero, this, true);
+			cb->startBattleI(hero, this, !regularUnitPlacement);
 		else
 			doVisit(hero);
 	}

+ 5 - 0
lib/mapObjects/CBank.h

@@ -22,6 +22,7 @@ class DLL_LINKAGE CBank : public CArmedInstance
 	ui32 daycounter;
 	ui32 resetDuration;
 	bool coastVisitable;
+	bool regularUnitPlacement;
 
 	void setPropertyDer(ObjProperty what, ObjPropertyID identifier) override;
 	void doVisit(const CGHeroInstance * hero) const;
@@ -50,6 +51,10 @@ public:
 		h & bankConfig;
 		h & resetDuration;
 		h & coastVisitable;
+		if (h.version >= Handler::Version::BANK_UNIT_PLACEMENT)
+			h & regularUnitPlacement;
+		else
+			regularUnitPlacement = false;
 	}
 
 	friend class CBankInstanceConstructor;

+ 2 - 1
lib/serializer/ESerializationVersion.h

@@ -46,6 +46,7 @@ enum class ESerializationVersion : int32_t
 	VOTING_SIMTURNS, // 841 - allow modification of simturns duration via vote
 
 	REMOVE_TEXT_CONTAINER_SIZE_T, // Fixed serialization of size_t from text containers
+	BANK_UNIT_PLACEMENT, // 842
 
-	CURRENT = REMOVE_TEXT_CONTAINER_SIZE_T
+	CURRENT = BANK_UNIT_PLACEMENT
 };