diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 03b62c7f3..bd807f8d4 100644 --- a/hch/CObjectHandler.cpp +++ b/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 >::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 diff --git a/int3.h b/int3.h index e1dc5d393..c2a24f8a3 100644 --- a/int3.h +++ b/int3.h @@ -89,7 +89,7 @@ public: } operator bool() const { - return slots.size()>0; + return slots.size() > 0; } void sweep() { diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index 12abeebb3..489ff8973 100644 --- a/lib/CGameState.cpp +++ b/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 += ", "; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 0d9a4d2c4..aa6c16dd5 100644 --- a/server/CGameHandler.cpp +++ b/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; } }