1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

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

This commit is contained in:
DjWarmonger 2009-09-17 06:19:27 +00:00
parent df6a7d680e
commit 7660e29751
4 changed files with 44 additions and 26 deletions

View File

@ -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

2
int3.h
View File

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

View File

@ -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 += ", ";

View File

@ -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;
}
}