1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/lib/mapObjectConstructors/CRewardableConstructor.cpp

66 lines
1.8 KiB
C++
Raw Normal View History

/*
* CRewardableConstructor.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 "CRewardableConstructor.h"
#include "../mapObjects/CRewardableObject.h"
#include "../CGeneralTextHandler.h"
#include "../IGameCallback.h"
VCMI_LIB_NAMESPACE_BEGIN
void CRewardableConstructor::initTypeData(const JsonNode & config)
{
objectInfo.init(config, getBaseTextID());
2023-04-29 22:59:02 +02:00
blockVisit = config["blockedVisitable"].Bool();
if (!config["name"].isNull())
VLC->generaltexth->registerString( config.meta, getNameTextID(), config["name"].String());
2023-04-29 22:59:02 +02:00
}
bool CRewardableConstructor::hasNameTextID() const
{
return !objectInfo.getParameters()["name"].isNull();
}
2024-01-01 16:37:48 +02:00
CGObjectInstance * CRewardableConstructor::create(IGameCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const
{
2024-01-01 16:37:48 +02:00
auto * ret = new CRewardableObject(cb);
preInitObject(ret);
ret->appearance = tmpl;
2023-04-29 22:59:02 +02:00
ret->blockVisit = blockVisit;
return ret;
}
void CRewardableConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
{
2023-04-29 22:59:02 +02:00
if(auto * rewardableObject = dynamic_cast<CRewardableObject*>(object))
{
objectInfo.configureObject(rewardableObject->configuration, rng, object->cb);
2023-04-30 15:13:07 +02:00
for(auto & rewardInfo : rewardableObject->configuration.info)
2023-04-29 22:59:02 +02:00
{
for (auto & bonus : rewardInfo.reward.bonuses)
{
bonus.source = BonusSource::OBJECT_TYPE;
bonus.sid = BonusSourceID(rewardableObject->ID);
2023-04-29 22:59:02 +02:00
}
}
2023-05-25 18:35:21 +02:00
assert(!rewardableObject->configuration.info.empty());
2023-04-29 22:59:02 +02:00
}
}
std::unique_ptr<IObjectInfo> CRewardableConstructor::getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const
{
2023-04-30 15:13:07 +02:00
return std::unique_ptr<IObjectInfo>(new Rewardable::Info(objectInfo));
}
VCMI_LIB_NAMESPACE_END