1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/lib/rewardable/Limiter.cpp
2023-05-01 01:15:48 +04:00

109 lines
2.1 KiB
C++

/*
* Limiter.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "Limiter.h"
#include "../IGameCallback.h"
#include "../CGameStateFwd.h"
#include "../CPlayerState.h"
VCMI_LIB_NAMESPACE_BEGIN
bool Rewardable::Limiter::heroAllowed(const CGHeroInstance * hero) const
{
if(dayOfWeek != 0)
{
if (IObjectInterface::cb->getDate(Date::DAY_OF_WEEK) != dayOfWeek)
return false;
}
if(daysPassed != 0)
{
if (IObjectInterface::cb->getDate(Date::DAY) < daysPassed)
return false;
}
for(const auto & reqStack : creatures)
{
size_t count = 0;
for(const auto & slot : hero->Slots())
{
const CStackInstance * heroStack = slot.second;
if (heroStack->type == reqStack.type)
count += heroStack->count;
}
if (count < reqStack.count) //not enough creatures of this kind
return false;
}
if(!IObjectInterface::cb->getPlayerState(hero->tempOwner)->resources.canAfford(resources))
return false;
if(heroLevel > static_cast<si32>(hero->level))
return false;
if(static_cast<TExpType>(heroExperience) > hero->exp)
return false;
if(manaPoints > hero->mana)
return false;
if(manaPercentage > 100 * hero->mana / hero->manaLimit())
return false;
for(size_t i=0; i<primary.size(); i++)
{
if(primary[i] > hero->getPrimSkillLevel(static_cast<PrimarySkill::PrimarySkill>(i)))
return false;
}
for(const auto & skill : secondary)
{
if (skill.second > hero->getSecSkillLevel(skill.first))
return false;
}
for(const auto & spell : spells)
{
if (!hero->spellbookContainsSpell(spell))
return false;
}
for(const auto & art : artifacts)
{
if (!hero->hasArt(art))
return false;
}
for(const auto & sublimiter : noneOf)
{
if (sublimiter->heroAllowed(hero))
return false;
}
for(const auto & sublimiter : allOf)
{
if (!sublimiter->heroAllowed(hero))
return false;
}
if(anyOf.empty())
return true;
for(const auto & sublimiter : anyOf)
{
if (sublimiter->heroAllowed(hero))
return true;
}
return false;
}
VCMI_LIB_NAMESPACE_END