2
0
Эх сурвалжийг харах

Bonus system: fix N_DAYS bonus duration

ArseniyShestakov 10 жил өмнө
parent
commit
5bfbd8526b

+ 18 - 0
lib/HeroBonus.cpp

@@ -763,6 +763,24 @@ void CBonusSystemNode::popBonuses(const CSelector &s)
 		child->popBonuses(s);
 }
 
+void CBonusSystemNode::updateBonuses(const CSelector &s)
+{
+	BonusList bl;
+	exportedBonuses.getBonuses(bl, s);
+	for(Bonus *b : bl)
+	{
+		if(b->duration & Bonus::N_DAYS)
+		{
+			b->turnsRemain--;
+			if(b->turnsRemain <= 0)
+				removeBonus(b);
+		}
+	}
+
+	for(CBonusSystemNode *child : children)
+		child->updateBonuses(s);
+}
+
 void CBonusSystemNode::addNewBonus(Bonus *b)
 {
 	assert(!vstd::contains(exportedBonuses,b));

+ 1 - 0
lib/HeroBonus.h

@@ -686,6 +686,7 @@ public:
 	//bool isLimitedOnUs(Bonus *b) const; //if bonus should be removed from list acquired from this node
 
 	void popBonuses(const CSelector &s);
+	void updateBonuses(const CSelector &s);
 	virtual std::string bonusToString(const Bonus *bonus, bool description) const {return "";}; //description or bonus name
 	virtual std::string nodeName() const;
 

+ 1 - 0
lib/NetPacksLib.cpp

@@ -1026,6 +1026,7 @@ DLL_LINKAGE void NewTurn::applyGs( CGameState *gs )
 	if(gs->getDate(Date::DAY_OF_WEEK) == 1) //new week
 		gs->globalEffects.popBonuses(Bonus::OneWeek); //works for children -> all game objs
 
+	gs->globalEffects.updateBonuses(Bonus::NDays);
 	//TODO not really a single root hierarchy, what about bonuses placed elsewhere? [not an issue with H3 mechanics but in the future...]
 
 	for(CGTownInstance* t : gs->map->towns)