From 7ae5e2b406900e1cdb89f61bc1ce2c9b111a8a57 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 25 Oct 2024 19:01:00 +0000 Subject: [PATCH] Added support for daily income to flaggable objects --- docs/modders/Map_Objects/Flaggable.md | 13 +++++++++++++ .../FlaggableInstanceConstructor.cpp | 7 +++++++ .../FlaggableInstanceConstructor.h | 7 +++++++ lib/mapObjects/FlaggableMapObject.cpp | 2 +- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/modders/Map_Objects/Flaggable.md b/docs/modders/Map_Objects/Flaggable.md index a833345a6..f11bfca79 100644 --- a/docs/modders/Map_Objects/Flaggable.md +++ b/docs/modders/Map_Objects/Flaggable.md @@ -2,6 +2,12 @@ Flaggable object are those that can be captured by a visiting hero. H3 examples are mines, dwellings, or lighthouse. +Currently, it is possible to make flaggable objects that provide player with: +- Any [Bonus](Bonus_Format.md) supported by bonus system +- Daily resources income (wood, ore, gold, etc) + +## Format description + ```jsonc { "baseObjectName" : { @@ -18,6 +24,13 @@ Flaggable object are those that can be captured by a visiting hero. H3 examples "bonuses" : { "firstBonus" : { BONUS FORMAT }, "secondBonus" : { BONUS FORMAT }, + }, + + // Resources that will be given to owner on every day + "dailyIncome" : { + "wood" : 2, + "ore" : 2, + "gold" : 1000 } } } diff --git a/lib/mapObjectConstructors/FlaggableInstanceConstructor.cpp b/lib/mapObjectConstructors/FlaggableInstanceConstructor.cpp index efa68af0d..eeac5ee13 100644 --- a/lib/mapObjectConstructors/FlaggableInstanceConstructor.cpp +++ b/lib/mapObjectConstructors/FlaggableInstanceConstructor.cpp @@ -34,6 +34,8 @@ void FlaggableInstanceConstructor::initTypeData(const JsonNode & config) VLC->generaltexth->registerString( config.getModScope(), visitMessageTextID, config["message"]); } } + + dailyIncome = ResourceSet(config["dailyIncome"]); } void FlaggableInstanceConstructor::initializeObject(FlaggableMapObject * flaggable) const @@ -50,4 +52,9 @@ const std::vector> & FlaggableInstanceConstructor::getPro return providedBonuses; } +const ResourceSet & FlaggableInstanceConstructor::getDailyIncome() const +{ + return dailyIncome; +} + VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjectConstructors/FlaggableInstanceConstructor.h b/lib/mapObjectConstructors/FlaggableInstanceConstructor.h index fde90501f..c0ad722fe 100644 --- a/lib/mapObjectConstructors/FlaggableInstanceConstructor.h +++ b/lib/mapObjectConstructors/FlaggableInstanceConstructor.h @@ -10,6 +10,8 @@ #pragma once #include "CDefaultObjectTypeHandler.h" + +#include "../ResourceSet.h" #include "../bonuses/Bonus.h" #include "../mapObjects/FlaggableMapObject.h" @@ -17,11 +19,15 @@ VCMI_LIB_NAMESPACE_BEGIN class FlaggableInstanceConstructor final : public CDefaultObjectTypeHandler { + /// List of bonuses that are provided by every map object of this type std::vector> providedBonuses; /// ID of message to show on hero visit std::string visitMessageTextID; + /// Amount of resources granted by this object to owner every day + ResourceSet dailyIncome; + protected: void initTypeData(const JsonNode & config) override; void initializeObject(FlaggableMapObject * object) const override; @@ -29,6 +35,7 @@ protected: public: const std::string & getVisitMessageTextID() const; const std::vector> & getProvidedBonuses() const; + const ResourceSet & getDailyIncome() const; }; VCMI_LIB_NAMESPACE_END diff --git a/lib/mapObjects/FlaggableMapObject.cpp b/lib/mapObjects/FlaggableMapObject.cpp index 40d1149b0..5b22650ae 100644 --- a/lib/mapObjects/FlaggableMapObject.cpp +++ b/lib/mapObjects/FlaggableMapObject.cpp @@ -25,7 +25,7 @@ const IOwnableObject * FlaggableMapObject::asOwnable() const ResourceSet FlaggableMapObject::dailyIncome() const { - return {}; + return getFlaggableHandler()->getDailyIncome(); } std::vector FlaggableMapObject::providedCreatures() const