mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-06 09:09:40 +02:00
Hill fort upgrade costs are now loaded from json
This commit is contained in:
@@ -39,11 +39,11 @@ public:
|
||||
return createTyped(tmpl);
|
||||
}
|
||||
|
||||
virtual void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override
|
||||
void configureObject(CGObjectInstance * object, CRandomGenerator & rng) const override
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override
|
||||
std::unique_ptr<IObjectInfo> getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const override
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "../mapObjectConstructors/CommonConstructors.h"
|
||||
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
|
||||
#include "../mapObjectConstructors/ShrineInstanceConstructor.h"
|
||||
#include "../mapObjectConstructors/HillFortInstanceConstructor.h"
|
||||
#include "../mapObjects/CQuest.h"
|
||||
#include "../mapObjects/CGPandoraBox.h"
|
||||
#include "../mapObjects/ObjectTemplate.h"
|
||||
@@ -46,6 +47,7 @@ CObjectClassesHandler::CObjectClassesHandler()
|
||||
SET_HANDLER_CLASS("boat", BoatInstanceConstructor);
|
||||
SET_HANDLER_CLASS("market", MarketInstanceConstructor);
|
||||
SET_HANDLER_CLASS("shrine", ShrineInstanceConstructor);
|
||||
SET_HANDLER_CLASS("hillFort", HillFortInstanceConstructor);
|
||||
|
||||
SET_HANDLER_CLASS("static", CObstacleConstructor);
|
||||
SET_HANDLER_CLASS("", CObstacleConstructor);
|
||||
@@ -87,7 +89,6 @@ CObjectClassesHandler::CObjectClassesHandler()
|
||||
SET_HANDLER("whirlpool", CGWhirlpool);
|
||||
SET_HANDLER("witch", CGWitchHut);
|
||||
SET_HANDLER("terrain", CGTerrainPatch);
|
||||
SET_HANDLER("hillFort", HillFort);
|
||||
|
||||
#undef SET_HANDLER_CLASS
|
||||
#undef SET_HANDLER
|
||||
|
||||
50
lib/mapObjectConstructors/HillFortInstanceConstructor.cpp
Normal file
50
lib/mapObjectConstructors/HillFortInstanceConstructor.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* HillFortInstanceConstructor.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 "HillFortInstanceConstructor.h"
|
||||
|
||||
#include "../mapObjects/MiscObjects.h"
|
||||
#include "IObjectInfo.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
void HillFortInstanceConstructor::initTypeData(const JsonNode & config)
|
||||
{
|
||||
parameters = config;
|
||||
}
|
||||
|
||||
CGObjectInstance * HillFortInstanceConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||
{
|
||||
HillFort * fort = new HillFort;
|
||||
|
||||
preInitObject(fort);
|
||||
|
||||
if(tmpl)
|
||||
fort->appearance = tmpl;
|
||||
|
||||
return fort;
|
||||
}
|
||||
|
||||
void HillFortInstanceConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
|
||||
{
|
||||
HillFort * fort = dynamic_cast<HillFort *>(object);
|
||||
|
||||
if(!fort)
|
||||
throw std::runtime_error("Unexpected object instance in HillFortInstanceConstructor!");
|
||||
|
||||
fort->upgradeCostPercentage = parameters["upgradeCostFactor"].convertTo<std::vector<int>>();
|
||||
}
|
||||
|
||||
std::unique_ptr<IObjectInfo> HillFortInstanceConstructor::getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
34
lib/mapObjectConstructors/HillFortInstanceConstructor.h
Normal file
34
lib/mapObjectConstructors/HillFortInstanceConstructor.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* HillFortInstanceConstructor.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 HillFortInstanceConstructor 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