1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +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

@ -71,6 +71,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/mapObjectConstructors/CommonConstructors.cpp
${MAIN_LIB_DIR}/mapObjectConstructors/CRewardableConstructor.cpp
${MAIN_LIB_DIR}/mapObjectConstructors/HillFortInstanceConstructor.cpp
${MAIN_LIB_DIR}/mapObjectConstructors/ShipyardInstanceConstructor.cpp
${MAIN_LIB_DIR}/mapObjectConstructors/ShrineInstanceConstructor.cpp
${MAIN_LIB_DIR}/mapObjects/CArmedInstance.cpp
@ -380,6 +381,7 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/mapObjectConstructors/HillFortInstanceConstructor.h
${MAIN_LIB_DIR}/mapObjectConstructors/IObjectInfo.h
${MAIN_LIB_DIR}/mapObjectConstructors/RandomMapInfo.h
${MAIN_LIB_DIR}/mapObjectConstructors/ShipyardInstanceConstructor.h
${MAIN_LIB_DIR}/mapObjectConstructors/ShrineInstanceConstructor.h
${MAIN_LIB_DIR}/mapObjectConstructors/SObjectSounds.h

View File

@ -488,7 +488,8 @@
"index" : 0,
"aiValue" : 1000,
"rmg" : {
}
},
"boat" : "boatCastle"
}
}
},

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

View File

@ -2174,11 +2174,6 @@ void HillFort::onHeroVisit(const CGHeroInstance * h) const
openWindow(EOpenWindowMode::HILL_FORT_WINDOW,id.getNum(),h->id.getNum());
}
void HillFort::initObj(CRandomGenerator & rand)
{
VLC->objtypeh->getHandlerFor(ID, subID)->configureObject(this, rand);
}
void HillFort::fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const
{
int32_t level = stack.type->getLevel();

View File

@ -15,7 +15,6 @@
VCMI_LIB_NAMESPACE_BEGIN
class CMap;
class HillFortInstanceConstructor;
// This one teleport-specific, but has to be available everywhere in callbacks and netpacks
// For now it's will be there till teleports code refactored and moved into own file
@ -459,12 +458,22 @@ public:
class DLL_LINKAGE CGShipyard : public CGObjectInstance, public IShipyard
{
public:
void getOutOffsets(std::vector<int3> &offsets) const override; //offsets to obj pos when we boat can be placed
friend class ShipyardInstanceConstructor;
BoatId createdBoat;
protected:
void getOutOffsets(std::vector<int3> & offsets) const override;
void onHeroVisit(const CGHeroInstance * h) const override;
const IObjectInterface * getObject() const override;
BoatId getBoatType() const override;
public:
template<typename Handler> void serialize(Handler & h, const int version)
{
h & static_cast<CGObjectInstance&>(*this);
h & createdBoat;
}
protected:
void serializeJsonOptions(JsonSerializeFormat & handler) override;
@ -558,7 +567,6 @@ class DLL_LINKAGE HillFort : public CGObjectInstance, public ICreatureUpgrader
std::vector<int> upgradeCostPercentage;
protected:
void initObj(CRandomGenerator & rand) override;
void onHeroVisit(const CGHeroInstance * h) const override;
void fillUpgradeInfo(UpgradeInfo & info, const CStackInstance &stack) const override;

View File

@ -1292,9 +1292,9 @@ CGObjectInstance * CMapLoaderH3M::readQuestGuard(const int3 & mapPosition)
return guard;
}
CGObjectInstance * CMapLoaderH3M::readShipyard(const int3 & mapPosition)
CGObjectInstance * CMapLoaderH3M::readShipyard(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
auto * object = new CGShipyard();
auto * object = readGeneric(mapPosition, objectTemplate);
setOwnerAndValidate(mapPosition, object, reader->readPlayer32());
return object;
}
@ -1448,7 +1448,7 @@ CGObjectInstance * CMapLoaderH3M::readObject(std::shared_ptr<const ObjectTemplat
return readQuestGuard(mapPosition);
case Obj::SHIPYARD:
return readShipyard(mapPosition);
return readShipyard(mapPosition, objectTemplate);
case Obj::HERO_PLACEHOLDER:
return readHeroPlaceholder(mapPosition);

View File

@ -180,7 +180,7 @@ private:
CGObjectInstance * readBorderGuard();
CGObjectInstance * readBorderGate(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
CGObjectInstance * readQuestGuard(const int3 & position);
CGObjectInstance * readShipyard(const int3 & mapPosition);
CGObjectInstance * readShipyard(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readLighthouse(const int3 & mapPosition);
CGObjectInstance * readGeneric(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readBank(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);

View File

@ -22,6 +22,7 @@
#include "../mapObjectConstructors/CommonConstructors.h"
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
#include "../mapObjectConstructors/HillFortInstanceConstructor.h"
#include "../mapObjectConstructors/ShipyardInstanceConstructor.h"
#include "../mapObjectConstructors/ShrineInstanceConstructor.h"
#include "../mapObjects/MapObjects.h"
#include "../mapObjects/CGTownBuilding.h"
@ -102,6 +103,7 @@ void registerTypesMapObjectTypes(Serializer &s)
s.template registerType<AObjectTypeHandler, MarketInstanceConstructor>();
s.template registerType<AObjectTypeHandler, CObstacleConstructor>();
s.template registerType<AObjectTypeHandler, ShrineInstanceConstructor>();
s.template registerType<AObjectTypeHandler, ShipyardInstanceConstructor>();
s.template registerType<AObjectTypeHandler, HillFortInstanceConstructor>();
#define REGISTER_GENERIC_HANDLER(TYPENAME) s.template registerType<AObjectTypeHandler, CDefaultObjectTypeHandler<TYPENAME> >()