From ee1c5e452f39bfe227c7aaffc5c5c0375877b5ba Mon Sep 17 00:00:00 2001 From: ArseniyShestakov Date: Mon, 9 Nov 2015 15:01:58 +0300 Subject: [PATCH] Bonus system: add CWillLastDays selector --- lib/HeroBonus.cpp | 1 + lib/HeroBonus.h | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index 765d6dc46..e9ac989a8 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -1201,6 +1201,7 @@ namespace Selector DLL_LINKAGE CSelectFieldEqual sourceType(&Bonus::source); DLL_LINKAGE CSelectFieldEqual effectRange(&Bonus::effectRange); DLL_LINKAGE CWillLastTurns turns; + DLL_LINKAGE CWillLastDays days; DLL_LINKAGE CSelectFieldAny anyRange(&Bonus::effectRange); CSelector DLL_LINKAGE typeSubtype(Bonus::BonusType Type, TBonusSubtype Subtype) diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index f930f63e0..188442ff9 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -821,6 +821,31 @@ public: } }; +class DLL_LINKAGE CWillLastDays +{ +public: + int daysRequested; + + bool operator()(const Bonus *bonus) const + { + if(daysRequested <= 0) + return true; + else if(bonus->duration & Bonus::ONE_DAY) + return false; + else if(bonus->duration & Bonus::N_DAYS) + { + return bonus->turnsRemain > daysRequested; + } + + return false; // TODO: ONE_WEEK need support for turnsRemain, but for now we'll exclude all unhandled durations + } + CWillLastDays& operator()(const int &setVal) + { + daysRequested = setVal; + return *this; + } +}; + //Stores multiple limiters. If any of them fails -> bonus is dropped. class DLL_LINKAGE LimiterList : public ILimiter { @@ -959,6 +984,7 @@ namespace Selector extern DLL_LINKAGE CSelectFieldEqual sourceType; extern DLL_LINKAGE CSelectFieldEqual effectRange; extern DLL_LINKAGE CWillLastTurns turns; + extern DLL_LINKAGE CWillLastDays days; extern DLL_LINKAGE CSelectFieldAny anyRange; CSelector DLL_LINKAGE typeSubtype(Bonus::BonusType Type, TBonusSubtype Subtype);