From 434da3ffe1442c621da863f7bf9ae721ddafc1f4 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 7 May 2025 19:49:26 +0300 Subject: [PATCH] Added `forceCombat` field for ambush-like objects --- lib/mapObjects/CRewardableObject.cpp | 24 +++++++++++++++--------- lib/mapObjects/CRewardableObject.h | 2 ++ lib/rewardable/Configuration.cpp | 1 + lib/rewardable/Configuration.h | 5 +++++ lib/rewardable/Info.cpp | 1 + 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index 9057ad4dc..a61df96be 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -52,7 +52,14 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *hero) const cb->sendAndApply(cov); } - if (isGuarded()) + if (!isGuarded()) + doHeroVisit(hero); + + if (configuration.forceCombat) + { + doStartBattle(hero); + } + else { auto guardedIndexes = getAvailableRewards(hero, Rewardable::EEventType::EVENT_GUARDED); auto guardedReward = configuration.info.at(guardedIndexes.at(0)); @@ -65,10 +72,6 @@ void CRewardableObject::onHeroVisit(const CGHeroInstance *hero) const cb->showBlockingDialog(this, &bd); } - else - { - doHeroVisit(hero); - } } void CRewardableObject::heroLevelUpDone(const CGHeroInstance *hero) const @@ -92,15 +95,18 @@ void CRewardableObject::garrisonDialogClosed(const CGHeroInstance *hero) const cb->eraseStack(StackLocation(id, stacks.begin()->first)); } +void CRewardableObject::doStartBattle(const CGHeroInstance * hero) const +{ + auto layout = BattleLayout::createLayout(cb, configuration.guardsLayout, hero, this); + cb->startBattle(hero, this, visitablePos(), hero, nullptr, layout, nullptr); +} + void CRewardableObject::blockingDialogAnswered(const CGHeroInstance * hero, int32_t answer) const { if(isGuarded()) { if (answer) - { - auto layout = BattleLayout::createLayout(cb, configuration.guardsLayout, hero, this); - cb->startBattle(hero, this, visitablePos(), hero, nullptr, layout, nullptr); - } + doStartBattle(hero); } else { diff --git a/lib/mapObjects/CRewardableObject.h b/lib/mapObjects/CRewardableObject.h index ec8535538..f52adec17 100644 --- a/lib/mapObjects/CRewardableObject.h +++ b/lib/mapObjects/CRewardableObject.h @@ -25,6 +25,8 @@ protected: /// reward selected by player, no serialize ui16 selectedReward = 0; + void doStartBattle(const CGHeroInstance * hero) const; + void grantReward(ui32 rewardID, const CGHeroInstance * hero) const override; void markAsVisited(const CGHeroInstance * hero) const override; diff --git a/lib/rewardable/Configuration.cpp b/lib/rewardable/Configuration.cpp index e866d627d..c097ec77c 100644 --- a/lib/rewardable/Configuration.cpp +++ b/lib/rewardable/Configuration.cpp @@ -103,6 +103,7 @@ void Rewardable::Configuration::serializeJson(JsonSerializeFormat & handler) handler.serializeStruct("resetParameters", resetParameters); handler.serializeBool("canRefuse", canRefuse); handler.serializeBool("showScoutedPreview", showScoutedPreview); + handler.serializeBool("forceCombat", forceCombat); handler.serializeBool("coastVisitable", coastVisitable); handler.serializeInt("infoWindowType", infoWindowType); } diff --git a/lib/rewardable/Configuration.h b/lib/rewardable/Configuration.h index 94424b30c..6d4586505 100644 --- a/lib/rewardable/Configuration.h +++ b/lib/rewardable/Configuration.h @@ -169,6 +169,9 @@ struct DLL_LINKAGE Configuration /// if true - player can refuse visiting an object (e.g. Tomb) bool canRefuse = false; + /// if set to true and object is guarded, then hero visit will immediately start combat without confirmation + bool forceCombat = false; + /// if true - right-clicking object will show preview of object rewards bool showScoutedPreview = false; @@ -200,6 +203,8 @@ struct DLL_LINKAGE Configuration h & variables; h & visitLimiter; h & canRefuse; + if (h.version >= Handler::Version::REWARDABLE_EXTENSIONS) + h & forceCombat; h & showScoutedPreview; h & infoWindowType; h & coastVisitable; diff --git a/lib/rewardable/Info.cpp b/lib/rewardable/Info.cpp index 9fe0c8409..409f7c3ca 100644 --- a/lib/rewardable/Info.cpp +++ b/lib/rewardable/Info.cpp @@ -458,6 +458,7 @@ void Rewardable::Info::configureObject(Rewardable::Configuration & object, vstd: object.canRefuse = parameters["canRefuse"].Bool(); object.showScoutedPreview = parameters["showScoutedPreview"].Bool(); + object.forceCombat = parameters["forceCombat"].Bool(); object.guardsLayout = parameters["guardsLayout"].String(); object.coastVisitable = parameters["coastVisitable"].Bool();