Browse Source

Fixed #565. Creature components will not get description if they quantity is set to zero.

DjWarmonger 15 years ago
parent
commit
6c3ad7fcae
5 changed files with 20 additions and 5 deletions
  1. 1 0
      client/Client.h
  2. 3 5
      hch/CObjectHandler.cpp
  3. 1 0
      lib/IGameCallback.h
  4. 14 0
      server/CGameHandler.cpp
  5. 1 0
      server/CGameHandler.h

+ 1 - 0
client/Client.h

@@ -86,6 +86,7 @@ public:
 	void giveResource(int player, int which, int val){};
 	void giveResource(int player, int which, int val){};
 	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {};
 	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {};
 	void takeCreatures (int objid, TSlots creatures){};
 	void takeCreatures (int objid, TSlots creatures){};
+	void changeCreatureType (int objid, TSlot slot, TCreature creature){};
 	void showCompInfo(ShowInInfobox * comp){};
 	void showCompInfo(ShowInInfobox * comp){};
 	void heroVisitCastle(int obj, int heroID){};
 	void heroVisitCastle(int obj, int heroID){};
 	void stopHeroVisitCastle(int obj, int heroID){};
 	void stopHeroVisitCastle(int obj, int heroID){};

+ 3 - 5
hch/CObjectHandler.cpp

@@ -4619,13 +4619,11 @@ void CGBonusingObject::onHeroVisit( const CGHeroInstance * h ) const
 		if (creatures.slots.size())
 		if (creatures.slots.size())
 		{
 		{
 			messageID = 138;
 			messageID = 138;
-			cb->takeCreatures(h->id, creatures.slots);
-			for (std::map<TSlot, CStackInstance>::iterator i = creatures.slots.begin(); i != creatures.slots.end(); i++)
+			iw.components.push_back(Component(Component::CREATURE,11,0,1));
+			for (TSlots::const_iterator i = creatures.slots.begin(); i != creatures.slots.end(); ++i)
 			{
 			{
-				i->second.setType(11);
+				cb->changeCreatureType(h->id, i->first, 11);
 			}
 			}
-			cb->giveCreatures(h->id, h, creatures); //suboptimal again, but creature sets are screwed in general
-			iw.components.push_back(Component(Component::CREATURE,11,0,1));
 		}
 		}
 		else
 		else
 			messageID = 137;
 			messageID = 137;

+ 1 - 0
lib/IGameCallback.h

@@ -87,6 +87,7 @@ public:
 	virtual void giveResource(int player, int which, int val)=0;
 	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, CCreatureSet creatures) =0;
 	virtual void takeCreatures (int objid, TSlots creatures) =0;
 	virtual void takeCreatures (int objid, TSlots creatures) =0;
+	virtual void changeCreatureType (int objid, TSlot slot, TCreature creature) =0;
 	virtual void showCompInfo(ShowInInfobox * comp)=0;
 	virtual void showCompInfo(ShowInInfobox * comp)=0;
 	virtual void heroVisitCastle(int obj, int heroID)=0;
 	virtual void heroVisitCastle(int obj, int heroID)=0;
 	virtual void stopHeroVisitCastle(int obj, int heroID)=0;
 	virtual void stopHeroVisitCastle(int obj, int heroID)=0;

+ 14 - 0
server/CGameHandler.cpp

@@ -2875,6 +2875,20 @@ bool CGameHandler::upgradeCreature( ui32 objid, ui8 pos, ui32 upgID )
 	return true;
 	return true;
 }
 }
 
 
+void CGameHandler::changeCreatureType (int objid, TSlot slot, TCreature creature)
+{
+	CArmedInstance *obj = static_cast<CArmedInstance*>(gs->map->objects[objid]);
+	if (obj)
+	{
+		SetGarrisons sg;
+		sg.garrs[objid] = obj->getArmy();
+		sg.garrs[objid].slots[slot].setType(creature);
+		sendAndApply(&sg);
+	}
+	else
+		tlog2 <<"Illegal call of changeCreatureType for non-armed instance!\n";	
+}
+
 bool CGameHandler::garrisonSwap( si32 tid )
 bool CGameHandler::garrisonSwap( si32 tid )
 {
 {
 	CGTownInstance *town = gs->getTown(tid);
 	CGTownInstance *town = gs->getTown(tid);

+ 1 - 0
server/CGameHandler.h

@@ -135,6 +135,7 @@ public:
 	void giveResource(int player, int which, int val);
 	void giveResource(int player, int which, int val);
 	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures);
 	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures);
 	void takeCreatures (int objid, TSlots creatures);
 	void takeCreatures (int objid, TSlots creatures);
+	void changeCreatureType (int objid, TSlot slot, TCreature creature);
 	void showCompInfo(ShowInInfobox * comp);
 	void showCompInfo(ShowInInfobox * comp);
 	void heroVisitCastle(int obj, int heroID);
 	void heroVisitCastle(int obj, int heroID);
 	void vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h);
 	void vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h);