1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Adventure map shipyard nwo has configurable boat type

This commit is contained in:
Ivan Savenko
2023-06-08 00:04:13 +03:00
parent 487f441f47
commit 4d947be287
11 changed files with 109 additions and 24 deletions

View File

@@ -21,13 +21,14 @@
#include "../JsonNode.h"
#include "../CSoundBase.h"
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
#include "../mapObjectConstructors/CRewardableConstructor.h"
#include "../mapObjectConstructors/CommonConstructors.h"
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
#include "../mapObjectConstructors/ShrineInstanceConstructor.h"
#include "../mapObjectConstructors/HillFortInstanceConstructor.h"
#include "../mapObjects/CQuest.h"
#include "../mapObjectConstructors/ShipyardInstanceConstructor.h"
#include "../mapObjectConstructors/ShrineInstanceConstructor.h"
#include "../mapObjects/CGPandoraBox.h"
#include "../mapObjects/CQuest.h"
#include "../mapObjects/ObjectTemplate.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -48,6 +49,7 @@ CObjectClassesHandler::CObjectClassesHandler()
SET_HANDLER_CLASS("market", MarketInstanceConstructor);
SET_HANDLER_CLASS("shrine", ShrineInstanceConstructor);
SET_HANDLER_CLASS("hillFort", HillFortInstanceConstructor);
SET_HANDLER_CLASS("shipyard", ShipyardInstanceConstructor);
SET_HANDLER_CLASS("static", CObstacleConstructor);
SET_HANDLER_CLASS("", CObstacleConstructor);
@@ -81,7 +83,6 @@ CObjectClassesHandler::CObjectClassesHandler()
SET_HANDLER("resource", CGResource);
SET_HANDLER("scholar", CGScholar);
SET_HANDLER("seerHut", CGSeerHut);
SET_HANDLER("shipyard", CGShipyard);
SET_HANDLER("sign", CGSignBottle);
SET_HANDLER("siren", CGSirens);
SET_HANDLER("monolith", CGMonolith);

View File

@@ -29,17 +29,12 @@ CGObjectInstance * HillFortInstanceConstructor::create(std::shared_ptr<const Obj
if(tmpl)
fort->appearance = tmpl;
fort->upgradeCostPercentage = parameters["upgradeCostFactor"].convertTo<std::vector<int>>();
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

View File

@@ -0,0 +1,47 @@
/*
* ShipyardInstanceConstructor.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 "ShipyardInstanceConstructor.h"
#include "../mapObjects/MiscObjects.h"
#include "IObjectInfo.h"
#include "../CModHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
void ShipyardInstanceConstructor::initTypeData(const JsonNode & config)
{
parameters = config;
}
CGObjectInstance * ShipyardInstanceConstructor::create(std::shared_ptr<const ObjectTemplate> tmpl) const
{
CGShipyard * shipyard = new CGShipyard;
preInitObject(shipyard);
if(tmpl)
shipyard->appearance = tmpl;
shipyard->createdBoat = BoatId(*VLC->modh->identifiers.getIdentifier("core:boat", parameters["boat"]));
return shipyard;
}
void ShipyardInstanceConstructor::configureObject(CGObjectInstance * object, CRandomGenerator & rng) const
{
}
std::unique_ptr<IObjectInfo> ShipyardInstanceConstructor::getObjectInfo(std::shared_ptr<const ObjectTemplate> tmpl) const
{
return nullptr;
}
VCMI_LIB_NAMESPACE_END

View File

@@ -0,0 +1,34 @@
/*
* ShipyardInstanceConstructor.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 ShipyardInstanceConstructor 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