2014-04-27 15:19:23 +03:00
|
|
|
/*
|
2014-06-05 20:26:50 +03:00
|
|
|
* CRewardableConstructor.cpp, part of VCMI engine
|
2014-04-27 15:19:23 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "CRewardableConstructor.h"
|
2023-04-30 02:39:31 +02:00
|
|
|
#include "CRewardableObject.h"
|
2023-03-30 21:29:58 +02:00
|
|
|
#include "../CGeneralTextHandler.h"
|
2023-04-30 02:39:31 +02:00
|
|
|
#include "../IGameCallback.h"
|
2014-04-27 20:37:53 +03:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2014-06-14 18:42:13 +03:00
|
|
|
void CRewardableConstructor::initTypeData(const JsonNode & config)
|
2014-05-16 23:50:02 +03:00
|
|
|
{
|
|
|
|
objectInfo.init(config);
|
2023-04-29 22:59:02 +02:00
|
|
|
blockVisit = config["blockedVisitable"].Bool();
|
2023-03-30 21:29:58 +02:00
|
|
|
|
|
|
|
if (!config["name"].isNull())
|
|
|
|
VLC->generaltexth->registerString( config.meta, getNameTextID(), config["name"].String());
|
2023-04-29 22:59:02 +02:00
|
|
|
|
2023-03-30 21:29:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CRewardableConstructor::hasNameTextID() const
|
|
|
|
{
|
|
|
|
return !objectInfo.getParameters()["name"].isNull();
|
2014-05-16 23:50:02 +03:00
|
|
|
}
|
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
CGObjectInstance * CRewardableConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
|
2014-05-16 23:50:02 +03:00
|
|
|
{
|
2023-02-12 22:39:17 +02:00
|
|
|
auto * ret = new CRewardableObject();
|
2015-11-14 15:50:29 +02:00
|
|
|
preInitObject(ret);
|
2014-05-16 23:50:02 +03:00
|
|
|
ret->appearance = tmpl;
|
2023-04-29 22:59:02 +02:00
|
|
|
ret->blockVisit = blockVisit;
|
2014-05-16 23:50:02 +03:00
|
|
|
return ret;
|
2014-04-27 20:37:53 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 14:19:47 +03:00
|
|
|
void CRewardableConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
|
2014-04-27 20:37:53 +03:00
|
|
|
{
|
2023-04-29 22:59:02 +02:00
|
|
|
if(auto * rewardableObject = dynamic_cast<CRewardableObject*>(object))
|
|
|
|
{
|
2023-04-30 15:13:07 +02:00
|
|
|
objectInfo.configureObject(rewardableObject->configuration, rng);
|
|
|
|
for(auto & rewardInfo : rewardableObject->configuration.info)
|
2023-04-29 22:59:02 +02:00
|
|
|
{
|
|
|
|
for (auto & bonus : rewardInfo.reward.bonuses)
|
|
|
|
{
|
|
|
|
bonus.source = Bonus::OBJECT;
|
|
|
|
bonus.sid = rewardableObject->ID;
|
|
|
|
//TODO: bonus.description = object->getObjectName();
|
|
|
|
if (bonus.type == Bonus::MORALE)
|
|
|
|
rewardInfo.reward.extraComponents.emplace_back(Component::EComponentType::MORALE, 0, bonus.val, 0);
|
|
|
|
if (bonus.type == Bonus::LUCK)
|
|
|
|
rewardInfo.reward.extraComponents.emplace_back(Component::EComponentType::LUCK, 0, bonus.val, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-27 20:37:53 +03:00
|
|
|
}
|
|
|
|
|
2022-09-11 15:12:35 +02:00
|
|
|
std::unique_ptr<IObjectInfo> CRewardableConstructor::getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const
|
2014-04-27 20:37:53 +03:00
|
|
|
{
|
2023-04-30 15:13:07 +02:00
|
|
|
return std::unique_ptr<IObjectInfo>(new Rewardable::Info(objectInfo));
|
2014-04-27 20:37:53 +03:00
|
|
|
}
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|