mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Spell shrines can now be configured in json
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "../mapObjectConstructors/CRewardableConstructor.h"
|
||||
#include "../mapObjectConstructors/CommonConstructors.h"
|
||||
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../mapObjectConstructors/ShrineInstanceConstructor.h"
|
||||
#include "../mapObjects/CQuest.h"
|
||||
#include "../mapObjects/CGPandoraBox.h"
|
||||
#include "../mapObjects/ObjectTemplate.h"
|
||||
@@ -44,6 +45,7 @@ CObjectClassesHandler::CObjectClassesHandler()
|
||||
SET_HANDLER_CLASS("bank", CBankInstanceConstructor);
|
||||
SET_HANDLER_CLASS("boat", BoatInstanceConstructor);
|
||||
SET_HANDLER_CLASS("market", MarketInstanceConstructor);
|
||||
SET_HANDLER_CLASS("shrine", ShrineInstanceConstructor);
|
||||
|
||||
SET_HANDLER_CLASS("static", CObstacleConstructor);
|
||||
SET_HANDLER_CLASS("", CObstacleConstructor);
|
||||
@@ -78,7 +80,6 @@ CObjectClassesHandler::CObjectClassesHandler()
|
||||
SET_HANDLER("scholar", CGScholar);
|
||||
SET_HANDLER("seerHut", CGSeerHut);
|
||||
SET_HANDLER("shipyard", CGShipyard);
|
||||
SET_HANDLER("shrine", CGShrine);
|
||||
SET_HANDLER("sign", CGSignBottle);
|
||||
SET_HANDLER("siren", CGSirens);
|
||||
SET_HANDLER("monolith", CGMonolith);
|
||||
|
||||
65
lib/mapObjectConstructors/ShrineInstanceConstructor.cpp
Normal file
65
lib/mapObjectConstructors/ShrineInstanceConstructor.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* ShrineInstanceConstructor.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 "ShrineInstanceConstructor.h"
|
||||
|
||||
#include "IObjectInfo.h"
|
||||
#include "../mapObjects/MiscObjects.h"
|
||||
#include "../JsonRandom.h"
|
||||
#include "../IGameCallback.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
void ShrineInstanceConstructor::initTypeData(const JsonNode & config)
|
||||
{
|
||||
parameters = config;
|
||||
}
|
||||
|
||||
CGObjectInstance * ShrineInstanceConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||
{
|
||||
CGShrine * shrine = new CGShrine;
|
||||
|
||||
preInitObject(shrine);
|
||||
|
||||
if(tmpl)
|
||||
shrine->appearance = tmpl;
|
||||
|
||||
return shrine;
|
||||
}
|
||||
|
||||
void ShrineInstanceConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
|
||||
{
|
||||
CGShrine * shrine = dynamic_cast<CGShrine*>(object);
|
||||
|
||||
if (!shrine)
|
||||
throw std::runtime_error("Unexpected object instance in ShrineInstanceConstructor!");
|
||||
|
||||
auto visitTextParameter = parameters["visitText"];
|
||||
|
||||
if (visitTextParameter.isNumber())
|
||||
shrine->visitText.addTxt(MetaString::ADVOB_TXT, static_cast<ui32>(visitTextParameter.Float()));
|
||||
else
|
||||
shrine->visitText << visitTextParameter.String();
|
||||
|
||||
if(shrine->spell == SpellID::NONE) // shrine has no predefined spell
|
||||
{
|
||||
std::vector<SpellID> possibilities;
|
||||
shrine->cb->getAllowedSpells(possibilities);
|
||||
|
||||
shrine->spell =JsonRandom::loadSpell(parameters["spell"], rng, possibilities);
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<IObjectInfo> ShrineInstanceConstructor::getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
34
lib/mapObjectConstructors/ShrineInstanceConstructor.h
Normal file
34
lib/mapObjectConstructors/ShrineInstanceConstructor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ShrineInstanceConstructor.h, 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
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "AObjectTypeHandler.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class ShrineInstanceConstructor final : public AObjectTypeHandler
|
||||
{
|
||||
JsonNode parameters;
|
||||
|
||||
protected:
|
||||
void initTypeData(const JsonNode & config) override;
|
||||
CGObjectInstance * create(std::shared_ptr<const ObjectTemplate> tmpl = nullptr) const override;
|
||||
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override;
|
||||
std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override;
|
||||
|
||||
public:
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & static_cast<AObjectTypeHandler&>(*this);
|
||||
h & parameters;
|
||||
}
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
Reference in New Issue
Block a user