1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

All objects that can be owned by player now implement IOwnableObject

This commit is contained in:
Ivan Savenko
2024-08-25 15:04:44 +00:00
parent a481f07daf
commit d49a61645c
18 changed files with 131 additions and 73 deletions

View File

@@ -181,7 +181,7 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
int dwellingBonus = 0;
if(const PlayerState *p = cb->getPlayerState(tempOwner, false))
{
dwellingBonus = getDwellingBonus(creatures[level].second, p->getDwellings());
dwellingBonus = getDwellingBonus(creatures[level].second, p->getOwnedObjects());
}
if(dwellingBonus)
ret.entries.emplace_back(VLC->generaltexth->allTexts[591], dwellingBonus); // \nExternal dwellings %+d
@@ -192,15 +192,18 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
return ret;
}
int CGTownInstance::getDwellingBonus(const std::vector<CreatureID>& creatureIds, const std::vector<const CGDwelling * >& dwellings) const
int CGTownInstance::getDwellingBonus(const std::vector<CreatureID>& creatureIds, const std::vector<const CGObjectInstance * >& dwellings) const
{
int totalBonus = 0;
for (const auto& dwelling : dwellings)
{
for (const auto& creature : dwelling->creatures)
{
totalBonus += vstd::contains(creatureIds, creature.second[0]) ? 1 : 0;
}
const auto & dwellingCreatures = dwelling->asOwnable()->providedCreatures();
bool hasMatch = false;
for (const auto& creature : dwellingCreatures)
hasMatch = vstd::contains(creatureIds, creature);
if (hasMatch)
totalBonus += 1;
}
return totalBonus;
}
@@ -230,9 +233,9 @@ TResources CGTownInstance::dailyIncome() const
return ret;
}
const IOwnableObject * CGTownInstance::asOwnable() const
std::vector<CreatureID> CGTownInstance::providedCreatures() const
{
return this;
return {};
}
bool CGTownInstance::hasFort() const