1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

vcmi: modernize lib/mapObjects

This commit is contained in:
Konstantin
2023-02-12 23:39:17 +03:00
parent b16f66477c
commit 5f181e25af
30 changed files with 647 additions and 775 deletions

View File

@@ -30,15 +30,10 @@ static std::string visitedTxt(const bool visited)
return VLC->generaltexth->allTexts[id];
}
CBank::CBank()
{
daycounter = 0;
resetDuration = 0;
}
CBank::~CBank()
{
}
//must be instantiated in .cpp file for access to complete types of all member fields
CBank::CBank() = default;
//must be instantiated in .cpp file for access to complete types of all member fields
CBank::~CBank() = default;
void CBank::initObj(CRandomGenerator & rand)
{
@@ -55,10 +50,10 @@ std::string CBank::getHoverText(PlayerColor player) const
void CBank::setConfig(const BankConfig & config)
{
bc.reset(new BankConfig(config));
bc = std::make_unique<BankConfig>(config);
clear(); // remove all stacks, if any
for (auto & stack : config.guards)
for(const auto & stack : config.guards)
setCreature (SlotID(stacksCount()), stack.type->getId(), stack.count);
}
@@ -194,7 +189,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
break;
}
cb->giveHeroBonus(&gbonus);
iw.components.push_back(Component(Component::MORALE, 0, -1, 0));
iw.components.emplace_back(Component::MORALE, 0, -1, 0);
iw.soundID = soundBase::GRAVEYARD;
break;
}
@@ -205,7 +200,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
gb.id = hero->id.getNum();
cb->giveHeroBonus(&gb);
textID = 107;
iw.components.push_back(Component(Component::LUCK, 0, -2, 0));
iw.components.emplace_back(Component::LUCK, 0, -2, 0);
break;
}
case Obj::CREATURE_BANK:
@@ -229,7 +224,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
{
if (bc->resources[it] != 0)
{
iw.components.push_back(Component(Component::RESOURCE, it, bc->resources[it], 0));
iw.components.emplace_back(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);
@@ -239,7 +234,7 @@ void CBank::doVisit(const CGHeroInstance * hero) const
//grant artifacts
for (auto & elem : bc->artifacts)
{
iw.components.push_back(Component(Component::ARTIFACT, elem, 0, 0));
iw.components.emplace_back(Component::ARTIFACT, elem, 0, 0);
loot << "%s";
loot.addReplacement(MetaString::ART_NAMES, elem);
cb->giveHeroNewArtifact(hero, VLC->arth->objects[elem], ArtifactPosition::FIRST_AVAILABLE);
@@ -276,14 +271,14 @@ void CBank::doVisit(const CGHeroInstance * hero) const
}
for(const SpellID & spellId : bc->spells)
{
auto spell = spellId.toSpell(VLC->spells());
const auto * spell = spellId.toSpell(VLC->spells());
iw.text.addTxt(MetaString::SPELL_NAME, spellId);
if(spell->getLevel() <= hero->maxSpellLevel())
{
if(hero->canLearnSpell(spell))
{
spells.insert(spellId);
iw.components.push_back(Component(Component::SPELL, spellId, 0, 0));
iw.components.emplace_back(Component::SPELL, spellId, 0, 0);
}
}
else
@@ -307,14 +302,14 @@ void CBank::doVisit(const CGHeroInstance * hero) const
//grant creatures
CCreatureSet ourArmy;
for (auto slot : bc->creatures)
for(const auto & slot : bc->creatures)
{
ourArmy.addToSlot(ourArmy.getSlotFor(slot.type->idNumber), slot.type->getId(), slot.count);
}
for (auto & elem : ourArmy.Slots())
for(const auto & elem : ourArmy.Slots())
{
iw.components.push_back(Component(*elem.second));
iw.components.emplace_back(*elem.second);
loot << "%s";
loot.addReplacement(*elem.second);
}