From 115439f16acd512c7f4fd81240615dc9b5f0c3be Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 11 Oct 2024 15:01:18 +0000 Subject: [PATCH 1/4] Fix town events not actually giving offered creatures --- server/processors/NewTurnProcessor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/processors/NewTurnProcessor.cpp b/server/processors/NewTurnProcessor.cpp index f87c380f4..a850cb99f 100644 --- a/server/processors/NewTurnProcessor.cpp +++ b/server/processors/NewTurnProcessor.cpp @@ -116,6 +116,8 @@ void NewTurnProcessor::handleTownEvents(const CGTownInstance * town) iw.components.emplace_back(ComponentType::CREATURE, town->creatures.at(i).second.back(), event.creatures.at(i)); } } + + gameHandler->sendAndApply(sac); //show dialog } gameHandler->sendAndApply(iw); //show dialog } From e221cdccabc38e8b95c71e77ee7a6e0cdf6eb2d8 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 11 Oct 2024 15:01:43 +0000 Subject: [PATCH 2/4] Fix initialization of hero type in map editor --- lib/mapObjects/CGHeroInstance.cpp | 6 +++++- mapeditor/inspector/inspector.cpp | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/mapObjects/CGHeroInstance.cpp b/lib/mapObjects/CGHeroInstance.cpp index caaf5081a..b31ff4190 100644 --- a/lib/mapObjects/CGHeroInstance.cpp +++ b/lib/mapObjects/CGHeroInstance.cpp @@ -309,7 +309,11 @@ const CHeroClass * CGHeroInstance::getHeroClass() const HeroClassID CGHeroInstance::getHeroClassID() const { - return getHeroType()->heroClass->getId(); + auto heroType = getHeroTypeID(); + if (heroType.hasValue()) + return getHeroType()->heroClass->getId(); + else + return HeroClassID(); } const CHero * CGHeroInstance::getHeroType() const diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index 0fb5859ec..4ad9c5eaf 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -139,6 +139,18 @@ void Initializer::initialize(CGHeroInstance * o) o->tempOwner = PlayerColor::NEUTRAL; } + if(o->ID == Obj::HERO) + { + for(auto const & t : VLC->heroh->objects) + { + if(t->heroClass->getId() == HeroClassID(o->subID)) + { + o->subID = t->getId(); + break; + } + } + } + if(o->getHeroTypeID().hasValue()) { o->gender = o->getHeroType()->gender; From d1e7cb72c24a6d8ccd32526cc9fa1251d76810e8 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 11 Oct 2024 15:02:14 +0000 Subject: [PATCH 3/4] Fix game gang on random map generation --- lib/mapObjects/CGObjectInstance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mapObjects/CGObjectInstance.cpp b/lib/mapObjects/CGObjectInstance.cpp index c9d7b3eea..aa902a452 100644 --- a/lib/mapObjects/CGObjectInstance.cpp +++ b/lib/mapObjects/CGObjectInstance.cpp @@ -208,7 +208,7 @@ int CGObjectInstance::getSightRadius() const int3 CGObjectInstance::getVisitableOffset() const { if (!isVisitable()) - throw std::runtime_error("Attempt to access visitable offset of a non-visitable object!"); + logGlobal->debug("Attempt to access visitable offset on a non-visitable object!"); return appearance->getVisitableOffset(); } @@ -308,7 +308,7 @@ void CGObjectInstance::onHeroVisit( const CGHeroInstance * h ) const int3 CGObjectInstance::visitablePos() const { if (!isVisitable()) - throw std::runtime_error("Attempt to access visitable position on a non-visitable object!"); + logGlobal->debug("Attempt to access visitable position on a non-visitable object!"); return pos - getVisitableOffset(); } From c55a75cc4e6fbf450cc9d72bc5e332dd23c23c8b Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 11 Oct 2024 15:02:48 +0000 Subject: [PATCH 4/4] Remove copy-pasted code in rewardable town building leading to hero not registered as visitor --- lib/mapObjects/CRewardableObject.cpp | 14 +------------- lib/mapObjects/TownBuildingInstance.cpp | 16 +--------------- lib/rewardable/Interface.cpp | 17 +++++++++++++++++ lib/rewardable/Interface.h | 2 ++ 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/lib/mapObjects/CRewardableObject.cpp b/lib/mapObjects/CRewardableObject.cpp index 80a9a5603..9c0d67378 100644 --- a/lib/mapObjects/CRewardableObject.cpp +++ b/lib/mapObjects/CRewardableObject.cpp @@ -95,19 +95,7 @@ void CRewardableObject::blockingDialogAnswered(const CGHeroInstance * hero, int3 } else { - if (answer == 0) - return; //Player refused - - if(answer > 0 && answer - 1 < configuration.info.size()) - { - auto list = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT); - markAsVisited(hero); - grantReward(list[answer - 1], hero); - } - else - { - throw std::runtime_error("Unhandled choice"); - } + onBlockingDialogAnswered(hero, answer); } } diff --git a/lib/mapObjects/TownBuildingInstance.cpp b/lib/mapObjects/TownBuildingInstance.cpp index 2b485ef6d..8b4a40e5c 100644 --- a/lib/mapObjects/TownBuildingInstance.cpp +++ b/lib/mapObjects/TownBuildingInstance.cpp @@ -131,21 +131,7 @@ void TownRewardableBuildingInstance::heroLevelUpDone(const CGHeroInstance *hero) void TownRewardableBuildingInstance::blockingDialogAnswered(const CGHeroInstance *hero, int32_t answer) const { - if(answer == 0) - return; // player refused - - if(visitors.find(hero->id) != visitors.end()) - return; // query not for this building - - if(answer > 0 && answer-1 < configuration.info.size()) - { - auto list = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT); - grantReward(list[answer - 1], hero); - } - else - { - throw std::runtime_error("Unhandled choice"); - } + onBlockingDialogAnswered(hero, answer); } void TownRewardableBuildingInstance::grantReward(ui32 rewardID, const CGHeroInstance * hero) const diff --git a/lib/rewardable/Interface.cpp b/lib/rewardable/Interface.cpp index 0634ba7c0..f67250efe 100644 --- a/lib/rewardable/Interface.cpp +++ b/lib/rewardable/Interface.cpp @@ -366,4 +366,21 @@ void Rewardable::Interface::doHeroVisit(const CGHeroInstance *h) const } } +void Rewardable::Interface::onBlockingDialogAnswered(const CGHeroInstance * hero, int32_t answer) const +{ + if (answer == 0) + return; //Player refused + + if(answer > 0 && answer - 1 < configuration.info.size()) + { + auto list = getAvailableRewards(hero, Rewardable::EEventType::EVENT_FIRST_VISIT); + markAsVisited(hero); + grantReward(list[answer - 1], hero); + } + else + { + throw std::runtime_error("Unhandled choice"); + } +} + VCMI_LIB_NAMESPACE_END diff --git a/lib/rewardable/Interface.h b/lib/rewardable/Interface.h index 5354fffaf..3fe764637 100644 --- a/lib/rewardable/Interface.h +++ b/lib/rewardable/Interface.h @@ -48,6 +48,8 @@ protected: virtual void markAsVisited(const CGHeroInstance * hero) const = 0; virtual void markAsScouted(const CGHeroInstance * hero) const = 0; virtual void grantReward(ui32 rewardID, const CGHeroInstance * hero) const = 0; + + void onBlockingDialogAnswered(const CGHeroInstance * hero, int32_t answer) const; public: /// filters list of visit info and returns rewards that can be granted to current hero