mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-24 03:47:18 +02:00
Creature banks display resonable info about gathered loot.
This commit is contained in:
parent
4f88871f94
commit
df6a7d680e
@ -4041,9 +4041,12 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
|
|||||||
{
|
{
|
||||||
int textID = -1;
|
int textID = -1;
|
||||||
InfoWindow iw;
|
InfoWindow iw;
|
||||||
|
iw.player = h->getOwner();
|
||||||
|
MetaString loot;
|
||||||
|
|
||||||
switch (ID)
|
switch (ID)
|
||||||
{
|
{
|
||||||
case 16: //generic bank
|
case 16: case 25: case 84:
|
||||||
textID = 34;
|
textID = 34;
|
||||||
break;
|
break;
|
||||||
case 24: //derelict ship
|
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));
|
iw.components.push_back (Component (Component::MORALE, 0 , -2, 0));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 25: //utopia
|
|
||||||
textID = 47;
|
|
||||||
break;
|
|
||||||
case 84: //crypt
|
|
||||||
textID = 121;
|
|
||||||
break;
|
|
||||||
case 85: //shipwreck
|
case 85: //shipwreck
|
||||||
if (bc->resources.size() != 0)
|
if (bc->resources.size() != 0)
|
||||||
textID = 124;
|
textID = 124;
|
||||||
@ -4071,36 +4068,57 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
iw.text.addTxt (MetaString::ADVOB_TXT, textID);
|
|
||||||
iw.player = h->getOwner();
|
|
||||||
//grant resources
|
//grant resources
|
||||||
for (int it = 0; it < bc->resources.size(); it++)
|
for (int it = 0; it < bc->resources.size(); it++)
|
||||||
{
|
{
|
||||||
if (bc->resources[it] != 0)
|
if (bc->resources[it] != 0)
|
||||||
{
|
{
|
||||||
iw.components.push_back (Component (Component::RESOURCE, it, 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]);
|
cb->giveResource (h->getOwner(), it, bc->resources[it]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//grant artifacts
|
//grant artifacts
|
||||||
for (std::vector<ui32>::const_iterator it = artifacts.begin(); it != artifacts.end(); it++)
|
for (std::vector<ui32>::const_iterator it = artifacts.begin(); it != artifacts.end(); it++)
|
||||||
{
|
{
|
||||||
iw.components.push_back (Component (Component::ARTIFACT, *it, 0, 0));
|
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);
|
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);
|
cb->showInfoDialog(&iw);
|
||||||
|
|
||||||
//grant creatures
|
//grant creatures
|
||||||
CCreatureSet ourArmy;
|
CCreatureSet ourArmy;
|
||||||
for (std::vector< std::pair <ui16, ui32> >::const_iterator it = bc->creatures.begin(); it != bc->creatures.end(); it++)
|
for (std::vector< std::pair <ui16, ui32> >::const_iterator it = bc->creatures.begin(); it != bc->creatures.end(); it++)
|
||||||
{
|
{
|
||||||
int slot = ourArmy.getSlotFor (it->second);
|
int slot = ourArmy.getSlotFor (it->first);
|
||||||
ourArmy.slots[slot] = *it; //assuming we're not going to add multiple stacks of same creature
|
ourArmy.slots[slot].first = it->first;
|
||||||
|
ourArmy.slots[slot].second += it->second;
|
||||||
}
|
}
|
||||||
cb->giveCreatures (id, h, &ourArmy);
|
cb->giveCreatures (id, h, &ourArmy);
|
||||||
cb->setObjProperty (id, 15, 0); //bc = NULL
|
cb->setObjProperty (id, 15, 0); //bc = NULL
|
||||||
}
|
}
|
||||||
else
|
else //in case of defeat
|
||||||
cb->setObjProperty (id, 14, ran()); //reset
|
cb->setObjProperty (id, 14, ran()); //reset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,17 +236,17 @@ DLL_EXPORT void MetaString::toString(std::string &dst) const
|
|||||||
dst += boost::lexical_cast<std::string>(numbers[nums++]);
|
dst += boost::lexical_cast<std::string>(numbers[nums++]);
|
||||||
break;
|
break;
|
||||||
case TREPLACE_ESTRING:
|
case TREPLACE_ESTRING:
|
||||||
dst.replace(dst.find("%s"), 2, exactStrings[exSt++]);
|
dst.replace (dst.find("%s"), 2, exactStrings[exSt++]);
|
||||||
break;
|
break;
|
||||||
case TREPLACE_LSTRING:
|
case TREPLACE_LSTRING:
|
||||||
{
|
{
|
||||||
std::string hlp;
|
std::string hlp;
|
||||||
getLocalString(localStrings[loSt++], hlp);
|
getLocalString(localStrings[loSt++], hlp);
|
||||||
dst.replace(dst.find("%s"), 2, hlp);
|
dst.replace (dst.find("%s"), 2, hlp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TREPLACE_NUMBER:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
tlog1 << "MetaString processing error!\n";
|
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)
|
static CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
|
||||||
{
|
{
|
||||||
CGObjectInstance * nobj;
|
CGObjectInstance * nobj;
|
||||||
|
@ -123,6 +123,7 @@ public:
|
|||||||
message.push_back(TREPLACE_NUMBER);
|
message.push_back(TREPLACE_NUMBER);
|
||||||
numbers.push_back(txt);
|
numbers.push_back(txt);
|
||||||
}
|
}
|
||||||
|
DLL_EXPORT std::string buildList () const;
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
exactStrings.clear();
|
exactStrings.clear();
|
||||||
|
@ -1566,7 +1566,7 @@ void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreature
|
|||||||
if (creatures->slots.size() <= 0)
|
if (creatures->slots.size() <= 0)
|
||||||
return;
|
return;
|
||||||
CCreatureSet heroArmy = h->army;
|
CCreatureSet heroArmy = h->army;
|
||||||
while(creatures)
|
while (creatures)
|
||||||
{
|
{
|
||||||
int slot = heroArmy.getSlotFor(creatures->slots.begin()->second.first);
|
int slot = heroArmy.getSlotFor(creatures->slots.begin()->second.first);
|
||||||
if(slot < 0)
|
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].first = creatures->slots.begin()->second.first;
|
||||||
heroArmy.slots[slot].second += creatures->slots.begin()->second.second;
|
heroArmy.slots[slot].second += creatures->slots.begin()->second.second;
|
||||||
creatures->slots.erase(creatures->slots.begin());
|
creatures->slots.erase(creatures->slots.begin());
|
||||||
|
//ourArmy.slots.erase(ourArmy.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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user