Преглед изворни кода

Creature banks are now functional, however there are some glitches listed on our board.

DjWarmonger пре 16 година
родитељ
комит
7660e29751
4 измењених фајлова са 44 додато и 26 уклоњено
  1. 35 15
      hch/CObjectHandler.cpp
  2. 1 1
      int3.h
  3. 1 1
      lib/CGameState.cpp
  4. 7 9
      server/CGameHandler.cpp

+ 35 - 15
hch/CObjectHandler.cpp

@@ -4078,9 +4078,6 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
 				loot << "%d %s";
 				loot.addReplacement (iw.components.back().val);
 				loot.addReplacement (MetaString::RES_NAMES, iw.components.back().subtype);
-				//loot << iw.components.back().val << " ";
-				//loot.addTxt (iw.components.back().val);
-				//loot.addTxt (MetaString::RES_NAMES, iw.components.back().subtype);
 				cb->giveResource (h->getOwner(), it, bc->resources[it]);
 			}		
 		}
@@ -4093,19 +4090,21 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
 			cb->giveHeroArtifact (*it, h->id ,-2);
 		}
 		//display loot
-		if (textID == 34)
+		if (!loot.message.empty())
 		{
-			iw.text.addTxt(MetaString::ADVOB_TXT,34);//Heaving defeated %s, you discover %s
-			iw.text.addReplacement(MetaString::CRE_PL_NAMES, result->casualties[1].begin()->first);
-			//std::string loot_final;
-			//loot.toString (loot_final);
-			iw.text.addReplacement (loot.buildList());
-			//iw.text.addReplacement(" %d %s%s%d %s");	
+			if (textID == 34)
+			{
+				iw.text.addTxt(MetaString::ADVOB_TXT, 34);//Heaving defeated %s, you discover %s
+				iw.text.addReplacement (MetaString::CRE_PL_NAMES, result->casualties[1].begin()->first);
+				iw.text.addReplacement (loot.buildList());
+			}
+			else
+				iw.text.addTxt (MetaString::ADVOB_TXT, textID);
+			cb->showInfoDialog(&iw);
 		}
-		else
-			iw.text.addTxt (MetaString::ADVOB_TXT, textID);
-
-		cb->showInfoDialog(&iw);
+		loot.clear();
+		iw.components.clear();
+		iw.text.clear();
 
 		//grant creatures
 		CCreatureSet ourArmy;
@@ -4115,7 +4114,28 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
 			ourArmy.slots[slot].first = it->first;
 			ourArmy.slots[slot].second += it->second;
 		}
-		cb->giveCreatures (id, h, &ourArmy);
+		for (std::map<si32,std::pair<ui32,si32> >::const_iterator i = ourArmy.slots.begin(); i != ourArmy.slots.end(); i++)
+		{
+			iw.components.push_back (Component(Component::CREATURE, i->second.first, i->second.second, 0));
+			loot << "%s";
+			if (i->second.second == 1)
+				loot.addReplacement (MetaString::CRE_SING_NAMES, i->second.first);
+			else
+				loot.addReplacement (MetaString::CRE_PL_NAMES, i->second.first);
+		}
+
+		if (ourArmy.slots.size())
+		{
+			if (ourArmy.slots.size() == 1 && ourArmy.slots.begin()->second.second == 1)
+				iw.text.addTxt (MetaString::ADVOB_TXT, 185);
+			else
+				iw.text.addTxt (MetaString::ADVOB_TXT, 186);
+
+			iw.text.addReplacement (loot.buildList());
+			iw.text.addReplacement (h->name);
+			cb->showInfoDialog(&iw);
+			cb->giveCreatures (id, h, &ourArmy);
+		}
 		cb->setObjProperty (id, 15, 0); //bc = NULL
 	}
 	else //in case of defeat

+ 1 - 1
int3.h

@@ -89,7 +89,7 @@ public:
 	}
 	operator bool() const
 	{
-		return slots.size()>0;
+		return slots.size() > 0;
 	}
 	void sweep()
 	{

+ 1 - 1
lib/CGameState.cpp

@@ -265,7 +265,7 @@ DLL_EXPORT std::string MetaString::buildList () const
 	{
 		if (i > 0 && message[i] == TEXACT_STRING || message[i] == TLOCAL_STRING)
 		{
-			if (i == message.size())
+			if (i == message.size() - 1)
 				lista += " and ";
 			else
 				lista += ", ";

+ 7 - 9
server/CGameHandler.cpp

@@ -1566,19 +1566,17 @@ void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreature
 	if (creatures->slots.size() <= 0)
 		return;
 	CCreatureSet heroArmy = h->army;
-	while (creatures)
+	while (*creatures)
 	{
-		int slot = heroArmy.getSlotFor(creatures->slots.begin()->second.first);
-		if(slot < 0)
+		int slot = heroArmy.getSlotFor (creatures->slots.begin()->second.first);
+		if (slot < 0)
 			break;
-
 		heroArmy.slots[slot].first = creatures->slots.begin()->second.first;
 		heroArmy.slots[slot].second += creatures->slots.begin()->second.second;
-		creatures->slots.erase(creatures->slots.begin());
-		//ourArmy.slots.erase(ourArmy.slots.begin());
+		creatures->slots.erase (creatures->slots.begin());
 	}
 
-	if(!creatures) //all creatures can be moved to hero army - do that
+	if (!*creatures) //all creatures can be moved to hero army - do that
 	{
 		SetGarrisons sg;
 		sg.garrs[h->id] = heroArmy;
@@ -1588,8 +1586,8 @@ void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreature
 	{
 		SetGarrisons sg;
 		sg.garrs[objid] = *creatures;
-		sendAndApply(&sg);
-		showGarrisonDialog(objid, h->id, true, 0);
+		sendAndApply (&sg);
+		showGarrisonDialog (objid, h->id, true, 0);
 		return;
 	}
 }