Pārlūkot izejas kodu

* Witch HutL After the first visit to the hut, right-click/hover on that hut mention the skill available.
* refactorings

Michał W. Urbańczyk 17 gadi atpakaļ
vecāks
revīzija
fd66234a39
5 mainītis faili ar 79 papildinājumiem un 32 dzēšanām
  1. 2 1
      CAdvmapInterface.cpp
  2. 5 28
      CGameState.cpp
  3. 0 1
      CGameState.h
  4. 61 0
      hch/CObjectHandler.cpp
  5. 11 2
      hch/CObjectHandler.h

+ 2 - 1
CAdvmapInterface.cpp

@@ -497,7 +497,8 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent)
 	std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
 	std::vector<std::string> temp = LOCPLINT->cb->getObjDescriptions(pom);
 	if (temp.size())
 	if (temp.size())
 	{
 	{
-		LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1)));
+		boost::replace_all(temp.back(),"\n"," ");
+		LOCPLINT->adventureInt->statusbar.print(temp.back());
 	}
 	}
 	else
 	else
 	{
 	{

+ 5 - 28
CGameState.cpp

@@ -852,7 +852,11 @@ void CGameState::applyNL(IPack * pack)
 	case 1001://set object property
 	case 1001://set object property
 		{
 		{
 			SetObjectProperty *p = static_cast<SetObjectProperty*>(pack);
 			SetObjectProperty *p = static_cast<SetObjectProperty*>(pack);
-			setObjProperty(p);
+			CGObjectInstance *obj = map->objects[p->id];
+			if(!obj)
+				tlog1 << "Wrong object ID - property cannot be set!\n";
+			else
+				obj->setProperty(p->what,p->val);
 			break;
 			break;
 		}
 		}
 	case 1002:
 	case 1002:
@@ -1789,33 +1793,6 @@ void CGameState::loadTownDInfos()
 	}
 	}
 }
 }
 
 
-void CGameState::setObjProperty( SetObjectProperty * p )
-{
-	CGObjectInstance *obj = map->objects[p->id];
-
-	switch(p->what)
-	{
-	case 1:
-		obj->tempOwner = p->val;
-		break;
-	case 2:
-		obj->blockVisit = p->val;
-		break;
-	case 3:
-		static_cast<CArmedInstance*>(obj)->army.slots[0].second = p->val;
-		break;
-	case 4: 
-		static_cast<CGVisitableOPH*>(obj)->visitors.insert(p->val);
-		break;
-	case 5:
-		static_cast<CGVisitableOPW*>(obj)->visited = p->val;
-		break;
-	case 6:
-		obj->ID = p->val;
-		break;
-	}
-}
-
 void CGameState::getNeighbours(int3 tile, std::vector<int3> &vec, bool onLand)
 void CGameState::getNeighbours(int3 tile, std::vector<int3> &vec, bool onLand)
 {
 {
 	vec.clear();
 	vec.clear();

+ 0 - 1
CGameState.h

@@ -228,7 +228,6 @@ private:
 	void loadTownDInfos();
 	void loadTownDInfos();
 	void applyNL(IPack * pack);
 	void applyNL(IPack * pack);
 
 
-	void setObjProperty( SetObjectProperty * p );
 	void apply(IPack * pack);
 	void apply(IPack * pack);
 	void randomizeObject(CGObjectInstance *cur);
 	void randomizeObject(CGObjectInstance *cur);
 	std::pair<int,int> pickObject(CGObjectInstance *obj);
 	std::pair<int,int> pickObject(CGObjectInstance *obj);

+ 61 - 0
hch/CObjectHandler.cpp

@@ -45,6 +45,9 @@ IObjectInterface::IObjectInterface()
 void IObjectInterface::initObj()
 void IObjectInterface::initObj()
 {}
 {}
 
 
+void IObjectInterface::setProperty( ui8 what, ui32 val )
+{}
+
 void CObjectHandler::loadObjects()
 void CObjectHandler::loadObjects()
 {
 {
 	tlog5 << "\t\tReading cregens \n";
 	tlog5 << "\t\tReading cregens \n";
@@ -181,6 +184,26 @@ void CGObjectInstance::initObj()
 {
 {
 }
 }
 
 
+void CGObjectInstance::setProperty( ui8 what, ui32 val )
+{
+	switch(what)
+	{
+	case 1:
+		tempOwner = val;
+		break;
+	case 2:
+		blockVisit = val;
+		break;
+	case 6:
+		ID = val;
+		break;
+	}
+	setPropertyDer(what, val);
+}
+
+void CGObjectInstance::setPropertyDer( ui8 what, ui32 val )
+{}
+
 int lowestSpeed(const CGHeroInstance * chi)
 int lowestSpeed(const CGHeroInstance * chi)
 {
 {
 	if(!chi->army.slots.size())
 	if(!chi->army.slots.size())
@@ -700,6 +723,11 @@ const HeroBonus * CGHeroInstance::getBonus( int from, int id ) const
 	return NULL;
 	return NULL;
 }
 }
 
 
+void CGHeroInstance::setPropertyDer( ui8 what, ui32 val )
+{
+	if(what == 3)
+		army.slots[0].second = val;
+}
 int CGTownInstance::getSightDistance() const //returns sight distance
 int CGTownInstance::getSightDistance() const //returns sight distance
 {
 {
 	return 10;
 	return 10;
@@ -1084,6 +1112,12 @@ void CGVisitableOPH::arenaSelected( int heroID, int primSkill ) const
 	cb->changePrimSkill(heroID,primSkill,2);
 	cb->changePrimSkill(heroID,primSkill,2);
 }
 }
 
 
+void CGVisitableOPH::setPropertyDer( ui8 what, ui32 val )
+{
+	if(what == 4)
+		visitors.insert(val);
+}
+
 bool CArmedInstance::needsLastStack() const
 bool CArmedInstance::needsLastStack() const
 {
 {
 	return false;
 	return false;
@@ -1342,6 +1376,12 @@ void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const
 	}
 	}
 }
 }
 
 
+void CGVisitableOPW::setPropertyDer( ui8 what, ui32 val )
+{
+	if(what == 5)
+		visited = val;
+}
+
 void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
 void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
 {
 {
 	int destinationid=-1;
 	int destinationid=-1;
@@ -1566,6 +1606,8 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
 {
 {
 	InfoWindow iw;
 	InfoWindow iw;
 	iw.player = h->getOwner();
 	iw.player = h->getOwner();
+	if(!vstd::contains(playersVisited,h->tempOwner))
+		cb->setObjProperty(id,10,h->tempOwner);
 
 
 	if(h->getSecSkillLevel(ability)) //you alredy know this skill
 	if(h->getSecSkillLevel(ability)) //you alredy know this skill
 	{
 	{
@@ -1588,6 +1630,25 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const
 	cb->showInfoDialog(&iw);
 	cb->showInfoDialog(&iw);
 }
 }
 
 
+const std::string & CGWitchHut::getHoverText() const
+{
+	hoverName = VLC->generaltexth->names[ID];
+	if(vstd::contains(playersVisited,cb->getCurrentPlayer())) //TODO: use local player, not current
+	{
+		hoverName += "\n" + VLC->generaltexth->allTexts[356]; // + (learn %s)
+		boost::algorithm::replace_first(hoverName,"%s",VLC->generaltexth->skillName[ability]);
+		if(cb->getSelectedHero(cb->getCurrentPlayer())->getSecSkillLevel(ability)) //hero knows that ability
+			hoverName += "\n\n" + VLC->generaltexth->allTexts[357]; // (Already learned)
+	}
+	return hoverName;
+}
+
+void CGWitchHut::setPropertyDer( ui8 what, ui32 val )
+{
+	if(what == 10)
+		playersVisited.insert(val);
+}
+
 void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
 void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
 {
 {
 
 

+ 11 - 2
hch/CObjectHandler.h

@@ -88,7 +88,8 @@ public:
 	virtual void onHeroVisit(const CGHeroInstance * h) const;
 	virtual void onHeroVisit(const CGHeroInstance * h) const;
 	virtual void onHeroLeave(const CGHeroInstance * h) const;
 	virtual void onHeroLeave(const CGHeroInstance * h) const;
 	virtual void newTurn() const;
 	virtual void newTurn() const;
-	virtual void initObj();
+	virtual void initObj(); //synchr
+	virtual void setProperty(ui8 what, ui32 val);//synchr
 };
 };
 
 
 class DLL_EXPORT CGObjectInstance : protected IObjectInterface
 class DLL_EXPORT CGObjectInstance : protected IObjectInterface
@@ -120,6 +121,8 @@ public:
 	virtual const std::string & getHoverText() const;
 	virtual const std::string & getHoverText() const;
 	//////////////////////////////////////////////////////////////////////////
 	//////////////////////////////////////////////////////////////////////////
 	void initObj();
 	void initObj();
+	void setProperty(ui8 what, ui32 val);//synchr
+	virtual void setPropertyDer(ui8 what, ui32 val);//synchr
 
 
 	friend class CGameHandler;
 	friend class CGameHandler;
 
 
@@ -239,6 +242,8 @@ public:
 	virtual ~CGHeroInstance();
 	virtual ~CGHeroInstance();
 
 
 	//////////////////////////////////////////////////////////////////////////
 	//////////////////////////////////////////////////////////////////////////
+
+	void setPropertyDer(ui8 what, ui32 val);//synchr
 	void initObj();
 	void initObj();
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void onHeroVisit(const CGHeroInstance * h) const;
 };
 };
@@ -321,6 +326,7 @@ public:
 	si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
 	si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
 	const std::string & getHoverText() const;
 	const std::string & getHoverText() const;
 
 
+	void setPropertyDer(ui8 what, ui32 val);//synchr
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void onNAHeroVisit(int heroID, bool alreadyVisited) const;
 	void onNAHeroVisit(int heroID, bool alreadyVisited) const;
 	void initObj();
 	void initObj();
@@ -422,9 +428,11 @@ class DLL_EXPORT CGWitchHut : public CGObjectInstance
 {
 {
 public:
 public:
 	std::vector<si32> allowedAbilities;
 	std::vector<si32> allowedAbilities;
-
 	ui32 ability;
 	ui32 ability;
+	std::set<ui8> playersVisited; //players who know what skill is given here (used for hover texts)
 
 
+	void setPropertyDer(ui8 what, ui32 val);//synchr
+	const std::string & getHoverText() const;
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void initObj();
 	void initObj();
 	template <typename Handler> void serialize(Handler &h, const int version)
 	template <typename Handler> void serialize(Handler &h, const int version)
@@ -580,6 +588,7 @@ class DLL_EXPORT CGVisitableOPW : public CGObjectInstance //objects visitable OP
 public:
 public:
 	ui8 visited; //true if object has been visited this week
 	ui8 visited; //true if object has been visited this week
 
 
+	void setPropertyDer(ui8 what, ui32 val);//synchr
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void onHeroVisit(const CGHeroInstance * h) const;
 	void newTurn() const;
 	void newTurn() const;