Przeglądaj źródła

Clear rewardable garrison after player is done picking units

Ivan Savenko 5 miesięcy temu
rodzic
commit
7fc1990282

+ 9 - 0
lib/mapObjects/CRewardableObject.cpp

@@ -21,6 +21,7 @@
 #include "../mapObjects/CGHeroInstance.h"
 #include "../networkPacks/PacksForClient.h"
 #include "../networkPacks/PacksForClientBattle.h"
+#include "../networkPacks/StackLocation.h"
 #include "../serializer/JsonSerializeFormat.h"
 
 #include <vstd/RNG.h>
@@ -83,6 +84,14 @@ void CRewardableObject::battleFinished(const CGHeroInstance *hero, const BattleR
 	}
 }
 
+void CRewardableObject::garrisonDialogClosed(const CGHeroInstance *hero) const
+{
+	// if visitor received creatures as rewards, but does not have free slots, he will leave some units
+	// inside rewardable object, which might get treated as guards later
+	while(!stacks.empty())
+		cb->eraseStack(StackLocation(id, stacks.begin()->first));
+}
+
 void CRewardableObject::blockingDialogAnswered(const CGHeroInstance * hero, int32_t answer) const
 {
 	if(isGuarded())

+ 1 - 0
lib/mapObjects/CRewardableObject.h

@@ -56,6 +56,7 @@ public:
 	void onHeroVisit(const CGHeroInstance *h) const override;
 
 	void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
+	void garrisonDialogClosed(const CGHeroInstance *hero) const override;
 
 	///possibly resets object state
 	void newTurn(vstd::RNG & rand) const override;