From d83566bc74e3fbdeef2a62b1749f8ab55670f8ad Mon Sep 17 00:00:00 2001 From: nordsoft Date: Tue, 18 Apr 2023 17:27:39 +0400 Subject: [PATCH] Add constructor for boat --- lib/mapObjects/CObjectClassesHandler.cpp | 2 +- lib/mapObjects/CommonConstructors.cpp | 20 ++++++++++++++++++++ lib/mapObjects/CommonConstructors.h | 16 ++++++++++++++++ lib/mapObjects/MiscObjects.h | 4 ++++ lib/registerTypes/RegisterTypes.h | 1 + 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index 3b142bb75..d123bfff8 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -39,6 +39,7 @@ CObjectClassesHandler::CObjectClassesHandler() SET_HANDLER_CLASS("hero", CHeroInstanceConstructor); SET_HANDLER_CLASS("town", CTownInstanceConstructor); SET_HANDLER_CLASS("bank", CBankInstanceConstructor); + SET_HANDLER_CLASS("boat", BoatInstanceConstructor); SET_HANDLER_CLASS("static", CObstacleConstructor); SET_HANDLER_CLASS("", CObstacleConstructor); @@ -54,7 +55,6 @@ CObjectClassesHandler::CObjectClassesHandler() SET_HANDLER("cartographer", CCartographer); SET_HANDLER("artifact", CGArtifact); SET_HANDLER("blackMarket", CGBlackMarket); - SET_HANDLER("boat", CGBoat); SET_HANDLER("borderGate", CGBorderGate); SET_HANDLER("borderGuard", CGBorderGuard); SET_HANDLER("monster", CGCreature); diff --git a/lib/mapObjects/CommonConstructors.cpp b/lib/mapObjects/CommonConstructors.cpp index e1512c78a..9fa8938dd 100644 --- a/lib/mapObjects/CommonConstructors.cpp +++ b/lib/mapObjects/CommonConstructors.cpp @@ -257,6 +257,26 @@ std::vector CDwellingInstanceConstructor::getProducedCreature return creatures; } +void BoatInstanceConstructor::initTypeData(const JsonNode & input) +{ + layer = EPathfindingLayer::EEPathfindingLayer::SAIL; + if(input["layer"].String() == "land") + layer = EPathfindingLayer::EEPathfindingLayer::LAND; + if(input["layer"].String() == "air") + layer = EPathfindingLayer::EEPathfindingLayer::AIR; + if(input["layer"].String() == "water") + layer = EPathfindingLayer::EEPathfindingLayer::WATER; + if(input["layer"].String() == "sail") + layer = EPathfindingLayer::EEPathfindingLayer::SAIL; +} + +CGObjectInstance * BoatInstanceConstructor::create(std::shared_ptr tmpl) const +{ + CGBoat * boat = createTyped(tmpl); + boat->layer = layer; + return boat; +} + bool CBankInstanceConstructor::hasNameTextID() const { return true; diff --git a/lib/mapObjects/CommonConstructors.h b/lib/mapObjects/CommonConstructors.h index b20693d6b..14bc36174 100644 --- a/lib/mapObjects/CommonConstructors.h +++ b/lib/mapObjects/CommonConstructors.h @@ -140,6 +140,22 @@ public: } }; +class BoatInstanceConstructor : public CDefaultObjectTypeHandler +{ +protected: + void initTypeData(const JsonNode & config) override; + + EPathfindingLayer::EEPathfindingLayer layer; + +public: + CGObjectInstance * create(std::shared_ptr tmpl = nullptr) const override; + + template void serialize(Handler &h, const int version) + { + h & static_cast&>(*this); + } +}; + struct BankConfig { ui32 value = 0; //overall value of given things diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index 83307441a..70afae18f 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -419,6 +419,8 @@ class DLL_LINKAGE CGBoat : public CGObjectInstance public: ui8 direction; const CGHeroInstance *hero; //hero on board + + EPathfindingLayer::EEPathfindingLayer layer; void initObj(CRandomGenerator & rand) override; @@ -426,12 +428,14 @@ public: { hero = nullptr; direction = 4; + layer = EPathfindingLayer::EEPathfindingLayer::SAIL; } template void serialize(Handler &h, const int version) { h & static_cast(*this); h & direction; h & hero; + h & layer; } }; diff --git a/lib/registerTypes/RegisterTypes.h b/lib/registerTypes/RegisterTypes.h index b489099e5..5cd0c5580 100644 --- a/lib/registerTypes/RegisterTypes.h +++ b/lib/registerTypes/RegisterTypes.h @@ -88,6 +88,7 @@ void registerTypesMapObjectTypes(Serializer &s) s.template registerType(); s.template registerType(); s.template registerType(); + s.template registerType(); s.template registerType(); #define REGISTER_GENERIC_HANDLER(TYPENAME) s.template registerType >()