Explorar o código

Creature banks display resonable info about gathered loot.

DjWarmonger %!s(int64=16) %!d(string=hai) anos
pai
achega
df6a7d680e
Modificáronse 4 ficheiros con 89 adicións e 18 borrados
  1. 32 14
      hch/CObjectHandler.cpp
  2. 54 3
      lib/CGameState.cpp
  3. 1 0
      lib/NetPacks.h
  4. 2 1
      server/CGameHandler.cpp

+ 32 - 14
hch/CObjectHandler.cpp

@@ -4041,9 +4041,12 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
 	{
 		int textID = -1;
 		InfoWindow iw;
+		iw.player = h->getOwner();
+		MetaString loot;
+
 		switch (ID)
 		{
-			case 16: //generic bank
+			case 16: case 25: case 84:
 				textID = 34;
 				break;
 			case 24: //derelict ship
@@ -4055,12 +4058,6 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
 					iw.components.push_back (Component (Component::MORALE, 0 , -2, 0));
 				}
 				break;
-			case 25: //utopia
-				textID = 47;
-				break;
-			case 84: //crypt
-				textID = 121;
-				break;
 			case 85: //shipwreck
 				if (bc->resources.size() != 0)
 					textID = 124;
@@ -4071,36 +4068,57 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
 				}
 				break;
 		}
-		iw.text.addTxt (MetaString::ADVOB_TXT, textID);
-		iw.player = h->getOwner();
+
 		//grant resources
 		for (int it = 0; it < bc->resources.size(); it++)
 		{	
 			if (bc->resources[it] != 0)
 			{
 				iw.components.push_back (Component (Component::RESOURCE, it, bc->resources[it], 0));
+				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]);
-			}
+			}		
 		}
 		//grant artifacts
 		for (std::vector<ui32>::const_iterator it = artifacts.begin(); it != artifacts.end(); it++)
 		{
 			iw.components.push_back (Component (Component::ARTIFACT, *it, 0, 0));
-			iw.text.addReplacement (MetaString::ART_NAMES, *it);
+			loot << "%s";
+			loot.addReplacement (MetaString::ART_NAMES, *it);
 			cb->giveHeroArtifact (*it, h->id ,-2);
 		}
+		//display loot
+		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);
+			//std::string loot_final;
+			//loot.toString (loot_final);
+			iw.text.addReplacement (loot.buildList());
+			//iw.text.addReplacement(" %d %s%s%d %s");	
+		}
+		else
+			iw.text.addTxt (MetaString::ADVOB_TXT, textID);
+
 		cb->showInfoDialog(&iw);
+
 		//grant creatures
 		CCreatureSet ourArmy;
 		for (std::vector< std::pair <ui16, ui32> >::const_iterator it = bc->creatures.begin(); it != bc->creatures.end(); it++)
 		{
-			int slot = ourArmy.getSlotFor (it->second);
-			ourArmy.slots[slot] = *it; //assuming we're not going to add multiple stacks of same creature
+			int slot = ourArmy.getSlotFor (it->first);
+			ourArmy.slots[slot].first = it->first;
+			ourArmy.slots[slot].second += it->second;
 		}
 		cb->giveCreatures (id, h, &ourArmy);
 		cb->setObjProperty (id, 15, 0); //bc = NULL
 	}
-	else
+	else //in case of defeat
 		cb->setObjProperty (id, 14, ran()); //reset
 }
 

+ 54 - 3
lib/CGameState.cpp

@@ -236,17 +236,17 @@ DLL_EXPORT void MetaString::toString(std::string &dst) const
 			dst += boost::lexical_cast<std::string>(numbers[nums++]);
 			break;
 		case TREPLACE_ESTRING:
-			dst.replace(dst.find("%s"), 2, exactStrings[exSt++]);
+			dst.replace (dst.find("%s"), 2, exactStrings[exSt++]);
 			break;
 		case TREPLACE_LSTRING:
 			{
 				std::string hlp;
 				getLocalString(localStrings[loSt++], hlp);
-				dst.replace(dst.find("%s"), 2, hlp);
+				dst.replace (dst.find("%s"), 2, hlp);
 			}
 			break;
 		case TREPLACE_NUMBER:
-			dst.replace(dst.find("%d"), 2, boost::lexical_cast<std::string>(numbers[nums++]));
+			dst.replace (dst.find("%d"), 2, boost::lexical_cast<std::string>(numbers[nums++]));
 			break;
 		default:
 			tlog1 << "MetaString processing error!\n";
@@ -255,6 +255,57 @@ DLL_EXPORT void MetaString::toString(std::string &dst) const
 	}
 }
 
+DLL_EXPORT std::string MetaString::buildList () const
+///used to handle loot from creature bank
+{
+
+	size_t exSt = 0, loSt = 0, nums = 0;
+	std::string lista;		
+	for (int i = 0; i < message.size(); ++i)
+	{
+		if (i > 0 && message[i] == TEXACT_STRING || message[i] == TLOCAL_STRING)
+		{
+			if (i == message.size())
+				lista += " and ";
+			else
+				lista += ", ";
+		}
+		switch (message[i])
+		{
+			case TEXACT_STRING:
+				lista += exactStrings[exSt++];
+				break;
+			case TLOCAL_STRING:
+			{
+				std::string hlp;
+				getLocalString (localStrings[loSt++], hlp);
+				lista += hlp;
+			}
+				break;
+			case TNUMBER:
+				lista += boost::lexical_cast<std::string>(numbers[nums++]);
+				break;
+			case TREPLACE_ESTRING:
+				lista.replace (lista.find("%s"), 2, exactStrings[exSt++]);
+				break;
+			case TREPLACE_LSTRING:
+			{
+				std::string hlp;
+				getLocalString (localStrings[loSt++], hlp);
+				lista.replace (lista.find("%s"), 2, hlp);
+			}
+				break;
+			case TREPLACE_NUMBER:
+				lista.replace (lista.find("%d"), 2, boost::lexical_cast<std::string>(numbers[nums++]));
+				break;
+			default:
+				tlog1 << "MetaString processing error!\n";
+		}
+
+	}
+	return lista;
+}
+
 static CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
 {
 	CGObjectInstance * nobj;

+ 1 - 0
lib/NetPacks.h

@@ -123,6 +123,7 @@ public:
 		message.push_back(TREPLACE_NUMBER);
 		numbers.push_back(txt);
 	}
+	DLL_EXPORT std::string buildList () const;
 	void clear()
 	{
 		exactStrings.clear();

+ 2 - 1
server/CGameHandler.cpp

@@ -1566,7 +1566,7 @@ 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)
@@ -1575,6 +1575,7 @@ void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreature
 		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());
 	}
 
 	if(!creatures) //all creatures can be moved to hero army - do that