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

Merge pull request #3354 from dydzio0614/antimagic-garrison

Add missing antimagic functionality to antimagic garrisons
This commit is contained in:
Ivan Savenko 2023-12-22 16:33:39 +02:00 committed by GitHub
commit c8d024ae11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 3 deletions

View File

@ -557,6 +557,15 @@ void BattleWindow::bSpellf()
LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[683]) LOCPLINT->showInfoDialog(boost::str(boost::format(CGI->generaltexth->allTexts[683])
% heroName % CGI->artifacts()->getByIndex(artID)->getNameTranslated())); % heroName % CGI->artifacts()->getByIndex(artID)->getNameTranslated()));
} }
else if(blockingBonus->source == BonusSource::OBJECT_TYPE)
{
if(blockingBonus->sid.as<MapObjectID>() == Obj::GARRISON || blockingBonus->sid.as<MapObjectID>() == Obj::GARRISON2)
LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[684]);
}
}
else
{
logGlobal->warn("Unexpected problem with readiness to cast spell");
} }
} }

View File

@ -45,8 +45,8 @@ CArmedInstance::CArmedInstance()
{ {
} }
CArmedInstance::CArmedInstance(bool isHypotetic): CArmedInstance::CArmedInstance(bool isHypothetic):
CBonusSystemNode(isHypotetic), CBonusSystemNode(isHypothetic),
nonEvilAlignmentMix(this, nonEvilAlignmentMixSelector), nonEvilAlignmentMix(this, nonEvilAlignmentMixSelector),
battle(nullptr) battle(nullptr)
{ {

View File

@ -43,7 +43,7 @@ public:
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
CArmedInstance(); CArmedInstance();
CArmedInstance(bool isHypotetic); CArmedInstance(bool isHypothetic);
PlayerColor getOwner() const override PlayerColor getOwner() const override
{ {

View File

@ -12,6 +12,7 @@
#include "MiscObjects.h" #include "MiscObjects.h"
#include "../ArtifactUtils.h" #include "../ArtifactUtils.h"
#include "../bonuses/Propagators.h"
#include "../constants/StringConstants.h" #include "../constants/StringConstants.h"
#include "../CConfigHandler.h" #include "../CConfigHandler.h"
#include "../CGeneralTextHandler.h" #include "../CGeneralTextHandler.h"
@ -1005,6 +1006,23 @@ void CGGarrison::serializeJsonOptions(JsonSerializeFormat& handler)
CArmedInstance::serializeJsonOptions(handler); CArmedInstance::serializeJsonOptions(handler);
} }
void CGGarrison::initObj(CRandomGenerator &rand)
{
if(this->subID == MapObjectSubID::decode(this->ID, "antiMagic"))
addAntimagicGarrisonBonus();
}
void CGGarrison::addAntimagicGarrisonBonus()
{
auto bonus = std::make_shared<Bonus>();
bonus->type = BonusType::BLOCK_ALL_MAGIC;
bonus->source = BonusSource::OBJECT_TYPE;
bonus->sid = BonusSourceID(this->ID);
bonus->propagator = std::make_shared<CPropagatorNodeType>(CBonusSystemNode::BATTLE);
bonus->duration = BonusDuration::PERMANENT;
this->addNewBonus(bonus);
}
void CGMagi::initObj(CRandomGenerator & rand) void CGMagi::initObj(CRandomGenerator & rand)
{ {
if (ID == Obj::EYE_OF_MAGI) if (ID == Obj::EYE_OF_MAGI)

View File

@ -60,6 +60,7 @@ class DLL_LINKAGE CGGarrison : public CArmedInstance
public: public:
bool removableUnits; bool removableUnits;
void initObj(CRandomGenerator &rand) override;
bool passableFor(PlayerColor color) const override; bool passableFor(PlayerColor color) const override;
void onHeroVisit(const CGHeroInstance * h) const override; void onHeroVisit(const CGHeroInstance * h) const override;
void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override; void battleFinished(const CGHeroInstance *hero, const BattleResult &result) const override;
@ -71,6 +72,7 @@ public:
} }
protected: protected:
void serializeJsonOptions(JsonSerializeFormat & handler) override; void serializeJsonOptions(JsonSerializeFormat & handler) override;
void addAntimagicGarrisonBonus();
}; };
class DLL_LINKAGE CGArtifact : public CArmedInstance class DLL_LINKAGE CGArtifact : public CArmedInstance