1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00
This commit is contained in:
DjWarmonger 2013-04-27 08:11:20 +00:00
parent 32c87f532f
commit a7ed3ee3d0
3 changed files with 24 additions and 4 deletions

View File

@ -5895,7 +5895,10 @@ void MoraleLuckBox::set(const IBonusBearer *node)
else else
{ {
for(int it=0; it < mrl.size(); it++) for(int it=0; it < mrl.size(); it++)
text += "\n" + mrl[it].second; {
if (mrl[it].first) //no bonuses with value 0
text += "\n" + mrl[it].second;
}
} }
} }

View File

@ -2459,6 +2459,21 @@ void CGTownInstance::deserializationFix()
// garrisonHero->attachTo(this); // garrisonHero->attachTo(this);
} }
void CGTownInstance::updateMoraleBonusFromArmy()
{
Bonus *b = getBonusList().getFirst(Selector::sourceType(Bonus::ARMY) && Selector::type(Bonus::MORALE));
if(!b)
{
b = new Bonus(Bonus::PERMANENT, Bonus::MORALE, Bonus::ARMY, 0, -1);
addNewBonus(b);
}
if (garrisonHero)
b->val = 0;
else
CArmedInstance::updateMoraleBonusFromArmy();
}
void CGTownInstance::recreateBuildingsBonuses() void CGTownInstance::recreateBuildingsBonuses()
{ {
static TPropagatorPtr playerProp(new CPropagatorNodeType(PLAYER)); static TPropagatorPtr playerProp(new CPropagatorNodeType(PLAYER));
@ -2590,6 +2605,7 @@ void CGTownInstance::setGarrisonedHero(CGHeroInstance *h)
garrisonHero->attachTo(p); garrisonHero->attachTo(p);
garrisonHero = NULL; garrisonHero = NULL;
} }
updateMoraleBonusFromArmy(); //avoid giving morale bonus for same army twice
} }
bool CGTownInstance::armedGarrison() const bool CGTownInstance::armedGarrison() const
@ -7041,7 +7057,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
hasUndead |= inst->hasBonusOfType(Bonus::UNDEAD); hasUndead |= inst->hasBonusOfType(Bonus::UNDEAD);
} }
size_t factionsInArmy = factions.size(); size_t factionsInArmy = factions.size(); //town garrison seems to take both sets into account
// Take Angelic Alliance troop-mixing freedom of non-evil units into account. // Take Angelic Alliance troop-mixing freedom of non-evil units into account.
if (hasBonusOfType(Bonus::NONEVIL_ALIGNMENT_MIX)) if (hasBonusOfType(Bonus::NONEVIL_ALIGNMENT_MIX))
@ -7062,7 +7078,7 @@ void CArmedInstance::updateMoraleBonusFromArmy()
b->val = +1; b->val = +1;
b->description = VLC->generaltexth->arraytxt[115]; //All troops of one alignment +1 b->description = VLC->generaltexth->arraytxt[115]; //All troops of one alignment +1
} }
else else if (factions.size()) // no bonus from empty garrison
{ {
b->val = 2 - factionsInArmy; b->val = 2 - factionsInArmy;
b->description = boost::str(boost::format(VLC->generaltexth->arraytxt[114]) % factionsInArmy % b->val); //Troops of %d alignments %d b->description = boost::str(boost::format(VLC->generaltexth->arraytxt[114]) % factionsInArmy % b->val); //Troops of %d alignments %d

View File

@ -262,7 +262,7 @@ public:
BattleInfo *battle; //set to the current battle, if engaged BattleInfo *battle; //set to the current battle, if engaged
void randomizeArmy(int type); void randomizeArmy(int type);
void updateMoraleBonusFromArmy(); virtual void updateMoraleBonusFromArmy();
void armyChanged() override; void armyChanged() override;
@ -620,6 +620,7 @@ public:
CBonusSystemNode *whatShouldBeAttached() override; CBonusSystemNode *whatShouldBeAttached() override;
std::string nodeName() const override; std::string nodeName() const override;
void updateMoraleBonusFromArmy() override;
void deserializationFix(); void deserializationFix();
void recreateBuildingsBonuses(); void recreateBuildingsBonuses();
bool addBonusIfBuilt(BuildingID building, Bonus::BonusType type, int val, TPropagatorPtr &prop, int subtype = -1); //returns true if building is built and bonus has been added bool addBonusIfBuilt(BuildingID building, Bonus::BonusType type, int val, TPropagatorPtr &prop, int subtype = -1); //returns true if building is built and bonus has been added