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-06-02 20:47:37 +02:00
|
|
|
|
|
|
|
#include "../mapObjects/CRewardableObject.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../texts/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
|
|
|
{
|
2023-07-19 21:25:52 +02:00
|
|
|
objectInfo.init(config, getBaseTextID());
|
2023-04-29 22:59:02 +02:00
|
|
|
blockVisit = config["blockedVisitable"].Bool();
|
2023-03-30 21:29:58 +02:00
|
|
|
|
|
|
|
if (!config["name"].isNull())
|
2024-02-13 14:34:16 +02:00
|
|
|
VLC->generaltexth->registerString( config.getModScope(), 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
|
|
|
}
|
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
CGObjectInstance * CRewardableConstructor::create(IGameCallback * cb, std::shared_ptr<const ObjectTemplate> tmpl) const
|
2014-05-16 23:50:02 +03:00
|
|
|
{
|
2024-01-01 16:37:48 +02:00
|
|
|
auto * ret = new CRewardableObject(cb);
|
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
|
|
|
}
|
|
|
|
|
2024-07-12 17:10:03 +02:00
|
|
|
Rewardable::Configuration CRewardableConstructor::generateConfiguration(IGameCallback * cb, vstd::RNG & rand, MapObjectID objectID) const
|
2014-04-27 20:37:53 +03:00
|
|
|
{
|
2024-07-12 17:10:03 +02:00
|
|
|
Rewardable::Configuration result;
|
|
|
|
objectInfo.configureObject(result, rand, cb);
|
|
|
|
|
|
|
|
for(auto & rewardInfo : result.info)
|
2023-04-29 22:59:02 +02:00
|
|
|
{
|
2024-07-12 17:10:03 +02:00
|
|
|
for (auto & bonus : rewardInfo.reward.bonuses)
|
2023-04-29 22:59:02 +02:00
|
|
|
{
|
2024-07-12 17:10:03 +02:00
|
|
|
bonus.source = BonusSource::OBJECT_TYPE;
|
|
|
|
bonus.sid = BonusSourceID(objectID);
|
2023-04-29 22:59:02 +02:00
|
|
|
}
|
2024-07-12 17:10:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRewardableConstructor::configureObject(CGObjectInstance * object, vstd::RNG & rng) const
|
|
|
|
{
|
|
|
|
if(auto * rewardableObject = dynamic_cast<CRewardableObject*>(object))
|
|
|
|
{
|
|
|
|
rewardableObject->configuration = generateConfiguration(object->cb, rng, object->ID);
|
|
|
|
|
2024-05-16 17:14:36 +02:00
|
|
|
if (rewardableObject->configuration.info.empty())
|
|
|
|
{
|
|
|
|
if (objectInfo.getParameters()["rewards"].isNull())
|
|
|
|
logMod->error("Object %s has invalid configuration! No defined rewards found!", getJsonKey());
|
|
|
|
else
|
2024-06-24 03:23:26 +02:00
|
|
|
logMod->error("Object %s has invalid configuration! Make sure that defined appear chances are continuous!", getJsonKey());
|
2024-05-16 17:14:36 +02:00
|
|
|
}
|
2023-04-29 22:59:02 +02:00
|
|
|
}
|
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
|