فهرست منبع

Support for Magic Spring

Optimized Pandora Box
DjWarmonger 16 سال پیش
والد
کامیت
91b4212c5f
7فایلهای تغییر یافته به همراه56 افزوده شده و 33 حذف شده
  1. 1 1
      client/Client.h
  2. 35 30
      hch/CObjectHandler.cpp
  3. 12 0
      hch/CObjectHandler.h
  4. 1 1
      lib/IGameCallback.h
  5. 1 0
      lib/RegisterTypes.cpp
  6. 5 0
      lib/map.cpp
  7. 1 1
      server/CGameHandler.cpp

+ 1 - 1
client/Client.h

@@ -99,7 +99,7 @@ public:
 	ui32 showBlockingDialog(BlockingDialog *iw){return 0;}; //synchronous version of above
 	void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
 	void giveResource(int player, int which, int val){};
-	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet *creatures){};
+	void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const {};
 	void showCompInfo(ShowInInfobox * comp){};
 	void heroVisitCastle(int obj, int heroID){};
 	void stopHeroVisitCastle(int obj, int heroID){};

+ 35 - 30
hch/CObjectHandler.cpp

@@ -1552,8 +1552,8 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
 		}
 		else
 		{
-			cb->setOwner(id, h->tempOwner);
 			removeCapitols (h->getOwner(), true);
+			cb->setOwner(id, h->tempOwner);
 		}
 	}
 	cb->heroVisitCastle(id, h->id);
@@ -2449,7 +2449,7 @@ void CGVisitableOPW::newTurn() const
 
 void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const
 {
-	int mid, sound = 0;
+	int mid, sound = 0; //message id, sound
 	switch (ID)
 	{
 	case 55: //mystical garden
@@ -3129,6 +3129,38 @@ void CGBonusingObject::initObj()
 	}
 }
 
+void CGMagicSpring::onHeroVisit(const CGHeroInstance * h) const
+{
+	int messageID;
+	InfoWindow iw;
+	iw.player = h->tempOwner;
+	iw.soundID = soundBase::GENIE;
+	if (!visited)
+	{
+		if (h->mana > h->manaLimit()) 
+			messageID = 76;
+		else
+		{
+			messageID = 74;
+			cb->setManaPoints (h->id, 2 * h->manaLimit());
+			cb->setObjProperty (id, 5, true);
+		}
+	}
+	else
+		messageID = 75;
+	iw.text << std::pair<ui8,ui32>(11,messageID);
+	cb->showInfoDialog(&iw);
+}
+const std::string & CGMagicSpring::getHoverText() const
+{
+	hoverName = VLC->generaltexth->names[ID];
+	if(!visited)
+		hoverName += " " + VLC->generaltexth->allTexts[353]; //not visited
+	else
+		hoverName += " " + VLC->generaltexth->allTexts[352]; //visited
+	return hoverName;
+}
+
 void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const
 {
 	int message;
@@ -3389,34 +3421,7 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
 		}
 		cb->showInfoDialog(&iw);
 	}
-
-	//check if creatures can be moved to hero army
-	CCreatureSet heroArmy = h->army;
-	CCreatureSet ourArmy = creatures;
-	while(ourArmy)
-	{
-		int slot = heroArmy.getSlotFor(ourArmy.slots.begin()->second.first);
-		if(slot < 0)
-			break;
-
-		heroArmy.slots[slot].first = ourArmy.slots.begin()->second.first;
-		heroArmy.slots[slot].second += ourArmy.slots.begin()->second.second;
-		ourArmy.slots.erase(ourArmy.slots.begin());
-	}
-
-	if(!ourArmy) //all creatures can be moved to hero army - do that
-	{
-		SetGarrisons sg;
-		sg.garrs[h->id] = heroArmy;
-		cb->sendAndApply(&sg);
-	}
-	else //show garrison window and let player pick creatures
-	{
-		SetGarrisons sg;
-		sg.garrs[id] = creatures;
-		cb->sendAndApply(&sg);
-		cb->showGarrisonDialog(id,h->id,true,boost::bind(&IGameCallback::removeObject,cb,id));
-	}
+	cb->giveCreatures (id, h, &creatures);
 
 	if(!afterBattle && message.size())
 	{

+ 12 - 0
hch/CObjectHandler.h

@@ -752,6 +752,18 @@ public:
 	}
 };
 
+class DLL_EXPORT CGMagicSpring : public CGVisitableOPW
+{///unfortunatelly, this one is quite different than others
+public:
+	void onHeroVisit(const CGHeroInstance * h) const;
+	const std::string & getHoverText() const;
+
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & static_cast<CGObjectInstance&>(*this);
+		h & visited;
+	}
+};
 class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
 {
 public:

+ 1 - 1
lib/IGameCallback.h

@@ -76,7 +76,7 @@ public:
 	virtual ui32 showBlockingDialog(BlockingDialog *iw) =0; //synchronous version of above //TODO:
 	virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window
 	virtual void giveResource(int player, int which, int val)=0;
-	virtual void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet *creatures)=0;
+	virtual void giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const=0;
 	virtual void showCompInfo(ShowInInfobox * comp)=0;
 	virtual void heroVisitCastle(int obj, int heroID)=0;
 	virtual void stopHeroVisitCastle(int obj, int heroID)=0;

+ 1 - 0
lib/RegisterTypes.cpp

@@ -42,6 +42,7 @@ void registerTypes1(Serializer &s)
 	s.template registerType<CGShrine>();
 	s.template registerType<CGQuestGuard>();
 	s.template registerType<CGBonusingObject>();
+	s.template registerType<CGMagicSpring>();
 	s.template registerType<CGMagicWell>();
 	s.template registerType<CGObservatory>();
 	s.template registerType<CGKeys>();

+ 5 - 0
lib/map.cpp

@@ -1948,6 +1948,11 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
 				nobj = new CCartographer();
 				break;
 			}
+		case 48: //Magic Spring
+			{
+				nobj = new CGMagicSpring();
+				break;
+			}
 		default:
 			nobj = new CGObjectInstance();
 		} //end of main switch

+ 1 - 1
server/CGameHandler.cpp

@@ -1570,7 +1570,7 @@ void CGameHandler::giveResource(int player, int which, int val)
 	sr.val = gs->players.find(player)->second.resources[which]+val;
 	sendAndApply(&sr);
 }
-void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet *creatures)
+void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, const CCreatureSet *creatures) const
 {
 	if (creatures->slots.size() <= 0)
 		return;