Bladeren bron

Some bugfixing, basic functionality of map objects seems to be working

Ivan Savenko 11 jaren geleden
bovenliggende
commit
ba5092d669
3 gewijzigde bestanden met toevoegingen van 29 en 15 verwijderingen
  1. 18 8
      lib/CObjectWithReward.cpp
  2. 3 0
      lib/NetPacks.h
  3. 8 7
      lib/registerTypes/RegisterTypes.h

+ 18 - 8
lib/CObjectWithReward.cpp

@@ -84,12 +84,16 @@ void CObjectWithReward::onHeroVisit(const CGHeroInstance *h) const
 	auto grantRewardWithMessage = [&](int index) -> void
 	{
 		grantReward(index, h);
-		InfoWindow iw;
-		iw.player = h->tempOwner;
-		iw.soundID = soundID;
-		iw.text = info[index].message;
-		info[index].reward.loadComponents(iw.components);
-		cb->showInfoDialog(&iw);
+		// show message only if it is not empty
+		if (!info[index].message.toString().empty())
+		{
+			InfoWindow iw;
+			iw.player = h->tempOwner;
+			iw.soundID = soundID;
+			iw.text = info[index].message;
+			info[index].reward.loadComponents(iw.components);
+			cb->showInfoDialog(&iw);
+		}
 	};
 
 	if (!wasVisited(h))
@@ -102,7 +106,10 @@ void CObjectWithReward::onHeroVisit(const CGHeroInstance *h) const
 				InfoWindow iw;
 				iw.player = h->tempOwner;
 				iw.soundID = soundID;
-				iw.text = onEmpty;
+				if (!onEmpty.toString().empty())
+					iw.text = onEmpty;
+				else
+					iw.text = onVisited;
 				cb->showInfoDialog(&iw);
 				onRewardGiven(h); // FIXME: dummy call to properly act on empty objects (e.g. Floatsam that must be removed after visit)
 				break;
@@ -142,7 +149,10 @@ void CObjectWithReward::onHeroVisit(const CGHeroInstance *h) const
 		InfoWindow iw;
 		iw.player = h->tempOwner;
 		iw.soundID = soundID;
-		iw.text = onVisited;
+		if (!onVisited.toString().empty())
+			iw.text = onVisited;
+		else
+			iw.text = onEmpty;
 		cb->showInfoDialog(&iw);
 	}
 }

+ 3 - 0
lib/NetPacks.h

@@ -1076,6 +1076,9 @@ struct ChangeObjectVisitors : public CPackForClient // 1003
 
 	DLL_LINKAGE void applyGs(CGameState *gs);
 
+	ChangeObjectVisitors()
+	{ type = 1003; }
+
 	ChangeObjectVisitors(ui32 mode, ObjectInstanceID object, ObjectInstanceID heroID = ObjectInstanceID(-1)):
 		mode(mode),
 		object(object),

+ 8 - 7
lib/registerTypes/RegisterTypes.h

@@ -5,7 +5,7 @@
 #include "../VCMI_Lib.h"
 #include "../CArtHandler.h"
 #include "../CObjectHandler.h"
-#include "../CObjectWithReward.h"
+#include "../CObjectWithReward.h"
 #include "../CGameState.h"
 #include "../CHeroHandler.h"
 #include "../CTownHandler.h"
@@ -80,12 +80,12 @@ void registerTypesMapObjects2(Serializer &s)
 		s.template registerType<CGTownBuilding, CTownBonus>();
 			s.template registerType<CGTownBuilding, COPWBonus>();
 
-	s.template registerType<CGObjectInstance, CObjectWithReward>();
-		s.template registerType<CObjectWithReward, CGPickable>();
-		s.template registerType<CObjectWithReward, CGVisitableOPH>();
-		s.template registerType<CObjectWithReward, CGVisitableOPW>();
-		s.template registerType<CObjectWithReward, CGOnceVisitable>();
-			s.template registerType<CGVisitableOPW, CGMagicSpring>();
+	s.template registerType<CGObjectInstance, CObjectWithReward>();
+		s.template registerType<CObjectWithReward, CGPickable>();
+		s.template registerType<CObjectWithReward, CGVisitableOPH>();
+		s.template registerType<CObjectWithReward, CGVisitableOPW>();
+		s.template registerType<CObjectWithReward, CGOnceVisitable>();
+			s.template registerType<CGVisitableOPW, CGMagicSpring>();
 
 	s.template registerType<CGObjectInstance, CPlayersVisited>();
 		s.template registerType<CPlayersVisited, CGWitchHut>();
@@ -188,6 +188,7 @@ void registerTypesClientPacks1(Serializer &s)
 	s.template registerType<CPackForClient, CenterView>();
 	s.template registerType<CPackForClient, HeroVisit>();
 	s.template registerType<CPackForClient, SetCommanderProperty>();
+	s.template registerType<CPackForClient, ChangeObjectVisitors>();
 }
 
 template<typename Serializer>