瀏覽代碼

Added support for daily income to flaggable objects

Ivan Savenko 1 年之前
父節點
當前提交
7ae5e2b406

+ 13 - 0
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
         }
       }
     }

+ 7 - 0
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<std::shared_ptr<Bonus>> & FlaggableInstanceConstructor::getPro
 	return providedBonuses;
 }
 
+const ResourceSet & FlaggableInstanceConstructor::getDailyIncome() const
+{
+	return dailyIncome;
+}
+
 VCMI_LIB_NAMESPACE_END

+ 7 - 0
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<FlaggableMapObject>
 {
+	/// List of bonuses that are provided by every map object of this type
 	std::vector<std::shared_ptr<Bonus>> 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<std::shared_ptr<Bonus>> & getProvidedBonuses() const;
+	const ResourceSet & getDailyIncome() const;
 };
 
 VCMI_LIB_NAMESPACE_END

+ 1 - 1
lib/mapObjects/FlaggableMapObject.cpp

@@ -25,7 +25,7 @@ const IOwnableObject * FlaggableMapObject::asOwnable() const
 
 ResourceSet FlaggableMapObject::dailyIncome() const
 {
-	return {};
+	return getFlaggableHandler()->getDailyIncome();
 }
 
 std::vector<CreatureID> FlaggableMapObject::providedCreatures() const