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

Fixing bugs for external dwelling bonus of Golem Factory (#382)

* Fixing bugs for external dwelling bonus of Golem Factory.

[Problem]
  The occupied Golem Factory on adventure map doesn't give
  the player corresponding weekly growth bonus.

[Solution]
  1. Add the dwelling (of multiple generators) to a player's dewelling set.
  2. Created helper function to calculate external dwelling bonus
  points.

[Test]
  Manual testing on the map, works fine.

https://bugs.vcmi.eu/view.php?id=2789
This commit is contained in:
Hao Hu 2017-10-07 07:42:33 -07:00 committed by ArseniyShestakov
parent 185631e94a
commit 9cc2464cf6
2 changed files with 18 additions and 4 deletions

View File

@ -157,7 +157,8 @@ void CGDwelling::setPropertyDer(ui8 what, ui32 val)
switch (what)
{
case ObjProperty::OWNER: //change owner
if (ID == Obj::CREATURE_GENERATOR1) //single generators
if (ID == Obj::CREATURE_GENERATOR1 || ID == Obj::CREATURE_GENERATOR2
|| ID == Obj::CREATURE_GENERATOR3 || ID == Obj::CREATURE_GENERATOR4)
{
if (tempOwner != PlayerColor::NEUTRAL)
{
@ -546,9 +547,7 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
int dwellingBonus = 0;
if(const PlayerState *p = cb->getPlayer(tempOwner, false))
{
for(const CGDwelling *dwelling : p->dwellings)
if(vstd::contains(creatures[level].second, dwelling->creatures[0].second[0]))
dwellingBonus++;
dwellingBonus = getDwellingBonus(creatures[level].second, p->dwellings);
}
if(dwellingBonus)
@ -570,6 +569,19 @@ GrowthInfo CGTownInstance::getGrowthInfo(int level) const
return ret;
}
int CGTownInstance::getDwellingBonus(const std::vector<CreatureID>& creatureIds, const std::vector<ConstTransitivePtr<CGDwelling> >& 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;
}
}
return totalBonus;
}
TResources CGTownInstance::dailyIncome() const
{
TResources ret;

View File

@ -294,4 +294,6 @@ public:
protected:
void setPropertyDer(ui8 what, ui32 val) override;
void serializeJsonOptions(JsonSerializeFormat & handler) override;
private:
int getDwellingBonus(const std::vector<CreatureID>& creatureIds, const std::vector<ConstTransitivePtr<CGDwelling> >& dwellings) const;
};