1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Added support for daily income to flaggable objects

This commit is contained in:
Ivan Savenko 2024-10-25 19:01:00 +00:00
parent 93096dc63c
commit 7ae5e2b406
4 changed files with 28 additions and 1 deletions

View File

@ -2,6 +2,12 @@
Flaggable object are those that can be captured by a visiting hero. H3 examples are mines, dwellings, or lighthouse. 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 ```jsonc
{ {
"baseObjectName" : { "baseObjectName" : {
@ -18,6 +24,13 @@ Flaggable object are those that can be captured by a visiting hero. H3 examples
"bonuses" : { "bonuses" : {
"firstBonus" : { BONUS FORMAT }, "firstBonus" : { BONUS FORMAT },
"secondBonus" : { BONUS FORMAT }, "secondBonus" : { BONUS FORMAT },
},
// Resources that will be given to owner on every day
"dailyIncome" : {
"wood" : 2,
"ore" : 2,
"gold" : 1000
} }
} }
} }

View File

@ -34,6 +34,8 @@ void FlaggableInstanceConstructor::initTypeData(const JsonNode & config)
VLC->generaltexth->registerString( config.getModScope(), visitMessageTextID, config["message"]); VLC->generaltexth->registerString( config.getModScope(), visitMessageTextID, config["message"]);
} }
} }
dailyIncome = ResourceSet(config["dailyIncome"]);
} }
void FlaggableInstanceConstructor::initializeObject(FlaggableMapObject * flaggable) const void FlaggableInstanceConstructor::initializeObject(FlaggableMapObject * flaggable) const
@ -50,4 +52,9 @@ const std::vector<std::shared_ptr<Bonus>> & FlaggableInstanceConstructor::getPro
return providedBonuses; return providedBonuses;
} }
const ResourceSet & FlaggableInstanceConstructor::getDailyIncome() const
{
return dailyIncome;
}
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -10,6 +10,8 @@
#pragma once #pragma once
#include "CDefaultObjectTypeHandler.h" #include "CDefaultObjectTypeHandler.h"
#include "../ResourceSet.h"
#include "../bonuses/Bonus.h" #include "../bonuses/Bonus.h"
#include "../mapObjects/FlaggableMapObject.h" #include "../mapObjects/FlaggableMapObject.h"
@ -17,11 +19,15 @@ VCMI_LIB_NAMESPACE_BEGIN
class FlaggableInstanceConstructor final : public CDefaultObjectTypeHandler<FlaggableMapObject> 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; std::vector<std::shared_ptr<Bonus>> providedBonuses;
/// ID of message to show on hero visit /// ID of message to show on hero visit
std::string visitMessageTextID; std::string visitMessageTextID;
/// Amount of resources granted by this object to owner every day
ResourceSet dailyIncome;
protected: protected:
void initTypeData(const JsonNode & config) override; void initTypeData(const JsonNode & config) override;
void initializeObject(FlaggableMapObject * object) const override; void initializeObject(FlaggableMapObject * object) const override;
@ -29,6 +35,7 @@ protected:
public: public:
const std::string & getVisitMessageTextID() const; const std::string & getVisitMessageTextID() const;
const std::vector<std::shared_ptr<Bonus>> & getProvidedBonuses() const; const std::vector<std::shared_ptr<Bonus>> & getProvidedBonuses() const;
const ResourceSet & getDailyIncome() const;
}; };
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

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