From 789c96d9b03d434933966279600d798411bc26a9 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 19 Jan 2024 16:17:59 +0200 Subject: [PATCH 1/5] Fixed binding lambda to a reference to a temporary on stack --- lib/rmg/modificators/TreasurePlacer.cpp | 40 ++++++++++++++----------- lib/rmg/modificators/TreasurePlacer.h | 2 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/rmg/modificators/TreasurePlacer.cpp b/lib/rmg/modificators/TreasurePlacer.cpp index 20c12e2eb..46a7d3b01 100644 --- a/lib/rmg/modificators/TreasurePlacer.cpp +++ b/lib/rmg/modificators/TreasurePlacer.cpp @@ -34,7 +34,7 @@ VCMI_LIB_NAMESPACE_BEGIN ObjectInfo::ObjectInfo(): - destroyObject([](){}) + destroyObject([](CGObjectInstance * obj){}) { } @@ -123,15 +123,9 @@ void TreasurePlacer::addAllPossibleObjects() continue; } - oi.generateObject = [i, this, prisonHeroPlacer, &oi]() -> CGObjectInstance* + oi.generateObject = [i, this, prisonHeroPlacer]() -> CGObjectInstance* { HeroTypeID hid = prisonHeroPlacer->drawRandomHero(); - oi.destroyObject = [hid, prisonHeroPlacer]() - { - // Hero can be used again - prisonHeroPlacer->restoreDrawnHero(hid); - }; - auto factory = VLC->objtypeh->getHandlerFor(Obj::PRISON, 0); auto* obj = dynamic_cast(factory->create()); @@ -141,6 +135,13 @@ void TreasurePlacer::addAllPossibleObjects() return obj; }; + oi.destroyObject = [prisonHeroPlacer](CGObjectInstance* obj) + { + // Hero can be used again + auto* hero = dynamic_cast(obj); + prisonHeroPlacer->restoreDrawnHero(hero->getHeroType()); + }; + oi.setTemplates(Obj::PRISON, 0, zone.getTerrainType()); oi.value = generator.getConfig().prisonValues[i]; oi.probability = 30; @@ -464,18 +465,20 @@ void TreasurePlacer::addAllPossibleObjects() RandomGeneratorUtil::randomShuffle(creatures, zone.getRand()); - auto setRandomArtifact = [qap, &oi](CGSeerHut * obj) + auto setRandomArtifact = [qap](CGSeerHut * obj) { ArtifactID artid = qap->drawRandomArtifact(); - oi.destroyObject = [artid, qap]() - { - // Artifact can be used again - qap->addRandomArtifact(artid); - qap->removeQuestArtifact(artid); - }; obj->quest->mission.artifacts.push_back(artid); qap->addQuestArtifact(artid); }; + auto destroyObject = [qap](CGObjectInstance * obj) + { + auto * seer = dynamic_cast(obj); + // Artifact can be used again + ArtifactID artid = seer->quest->mission.artifacts.front(); + qap->addRandomArtifact(artid); + qap->removeQuestArtifact(artid); + }; for(int i = 0; i < static_cast(creatures.size()); i++) { @@ -502,6 +505,7 @@ void TreasurePlacer::addAllPossibleObjects() return obj; }; + oi.destroyObject = destroyObject; oi.probability = 3; oi.setTemplates(Obj::SEER_HUT, randomAppearance, zone.getTerrainType()); oi.value = static_cast(((2 * (creature->getAIValue()) * creaturesAmount * (1 + static_cast(map.getZoneCount(creature->getFaction())) / map.getTotalZoneCount())) - 4000) / 3); @@ -546,6 +550,7 @@ void TreasurePlacer::addAllPossibleObjects() return obj; }; + oi.destroyObject = destroyObject; if(!oi.templates.empty()) possibleSeerHuts.push_back(oi); @@ -564,6 +569,7 @@ void TreasurePlacer::addAllPossibleObjects() return obj; }; + oi.destroyObject = destroyObject; if(!oi.templates.empty()) possibleSeerHuts.push_back(oi); @@ -670,7 +676,7 @@ rmg::Object TreasurePlacer::constructTreasurePile(const std::vector if(oi->templates.empty()) { logGlobal->warn("Deleting randomized object with no templates: %s", object->getObjectName()); - oi->destroyObject(); + oi->destroyObject(object); delete object; continue; } @@ -831,7 +837,7 @@ void TreasurePlacer::createTreasures(ObjectManager& manager) { for (auto* oi : treasurePile) { - oi->destroyObject(); + //oi->destroyObject(); oi->maxPerZone++; } }; diff --git a/lib/rmg/modificators/TreasurePlacer.h b/lib/rmg/modificators/TreasurePlacer.h index ec87bfe8d..8c6a6c316 100644 --- a/lib/rmg/modificators/TreasurePlacer.h +++ b/lib/rmg/modificators/TreasurePlacer.h @@ -30,7 +30,7 @@ struct ObjectInfo ui32 maxPerZone = 1; //ui32 maxPerMap; //unused std::function generateObject; - std::function destroyObject; + std::function destroyObject; void setTemplates(MapObjectID type, MapObjectSubID subtype, TerrainId terrain); }; From 2886d421abbba8e9e30da273276c6a8834e89d75 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 19 Jan 2024 16:18:13 +0200 Subject: [PATCH 2/5] Version bump --- android/vcmi-app/build.gradle | 4 ++-- cmake_modules/VersionDefinition.cmake | 2 +- debian/changelog | 6 ++++++ launcher/eu.vcmi.VCMI.metainfo.xml | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/android/vcmi-app/build.gradle b/android/vcmi-app/build.gradle index fea14c8d2..f4c216501 100644 --- a/android/vcmi-app/build.gradle +++ b/android/vcmi-app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "is.xyz.vcmi" minSdk 19 targetSdk 33 - versionCode 1430 - versionName "1.4.3" + versionCode 1440 + versionName "1.4.4" setProperty("archivesBaseName", "vcmi") } diff --git a/cmake_modules/VersionDefinition.cmake b/cmake_modules/VersionDefinition.cmake index 203958907..14867224a 100644 --- a/cmake_modules/VersionDefinition.cmake +++ b/cmake_modules/VersionDefinition.cmake @@ -1,6 +1,6 @@ set(VCMI_VERSION_MAJOR 1) set(VCMI_VERSION_MINOR 4) -set(VCMI_VERSION_PATCH 3) +set(VCMI_VERSION_PATCH 4) add_definitions( -DVCMI_VERSION_MAJOR=${VCMI_VERSION_MAJOR} -DVCMI_VERSION_MINOR=${VCMI_VERSION_MINOR} diff --git a/debian/changelog b/debian/changelog index ffac0ac51..144b17e94 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vcmi (1.4.4) jammy; urgency=medium + + * New upstream release + + -- Ivan Savenko Sat, 20 Jan 2024 12:00:00 +0200 + vcmi (1.4.3) jammy; urgency=medium * New upstream release diff --git a/launcher/eu.vcmi.VCMI.metainfo.xml b/launcher/eu.vcmi.VCMI.metainfo.xml index 54a0337b8..c043968f3 100644 --- a/launcher/eu.vcmi.VCMI.metainfo.xml +++ b/launcher/eu.vcmi.VCMI.metainfo.xml @@ -76,7 +76,8 @@ - + + From 44d3629028c9e95936d86c1e0086f90cc3602787 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 19 Jan 2024 16:30:15 +0200 Subject: [PATCH 3/5] Fix schema --- config/schemas/spell.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/schemas/spell.json b/config/schemas/spell.json index 8a29cd88b..a94ed65d3 100644 --- a/config/schemas/spell.json +++ b/config/schemas/spell.json @@ -166,7 +166,10 @@ "defaultGainChance" : { "type" : "number", "description" : "Gain chance by default for all factions" - + }, + "canCastOnSelf" : { + "type" : "boolean", + "description" : "If used as creature spell, unit can cast this spell on itself" }, "gainChance" : { "type" : "object", From aa02d5787ae04c0430b44042c4fec160ed1bef57 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 19 Jan 2024 17:26:51 +0200 Subject: [PATCH 4/5] Better solution for rmg crash fix --- lib/rmg/RmgObject.cpp | 3 +++ lib/rmg/RmgObject.h | 1 + lib/rmg/modificators/TreasurePlacer.cpp | 3 +-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/rmg/RmgObject.cpp b/lib/rmg/RmgObject.cpp index fcc593801..d55b481fd 100644 --- a/lib/rmg/RmgObject.cpp +++ b/lib/rmg/RmgObject.cpp @@ -138,6 +138,9 @@ void Object::Instance::setTemplate(TerrainId terrain, CRandomGenerator & rng) void Object::Instance::clear() { + if (onCleared) + onCleared(&dObject); + delete &dObject; dBlockedAreaCache.clear(); dAccessibleAreaCache.clear(); diff --git a/lib/rmg/RmgObject.h b/lib/rmg/RmgObject.h index b97cde6db..bdb9682e3 100644 --- a/lib/rmg/RmgObject.h +++ b/lib/rmg/RmgObject.h @@ -51,6 +51,7 @@ public: void finalize(RmgMap & map, CRandomGenerator &); //cache invalidation void clear(); + std::function onCleared; private: mutable Area dBlockedAreaCache; int3 dPosition; diff --git a/lib/rmg/modificators/TreasurePlacer.cpp b/lib/rmg/modificators/TreasurePlacer.cpp index 46a7d3b01..7abef254d 100644 --- a/lib/rmg/modificators/TreasurePlacer.cpp +++ b/lib/rmg/modificators/TreasurePlacer.cpp @@ -672,7 +672,6 @@ rmg::Object TreasurePlacer::constructTreasurePile(const std::vector } auto * object = oi->generateObject(); - if(oi->templates.empty()) { logGlobal->warn("Deleting randomized object with no templates: %s", object->getObjectName()); @@ -701,6 +700,7 @@ rmg::Object TreasurePlacer::constructTreasurePile(const std::vector } auto & instance = rmgObject.addInstance(*object); + instance.onCleared = oi->destroyObject; do { @@ -837,7 +837,6 @@ void TreasurePlacer::createTreasures(ObjectManager& manager) { for (auto* oi : treasurePile) { - //oi->destroyObject(); oi->maxPerZone++; } }; From b5ef782fe1cc4003e2d496434fcfe8b2e1d3a44d Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Fri, 19 Jan 2024 17:31:53 +0200 Subject: [PATCH 5/5] Fix key value to match specs --- launcher/vcmilauncher.desktop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/vcmilauncher.desktop b/launcher/vcmilauncher.desktop index cd465c47b..ad792e8bb 100644 --- a/launcher/vcmilauncher.desktop +++ b/launcher/vcmilauncher.desktop @@ -12,4 +12,4 @@ Exec=vcmilauncher Categories=Game;StrategyGame; Version=1.5 Keywords=heroes of might and magic;heroes;homm;homm3;strategy; -SingleMainWindow=yes +SingleMainWindow=true