From 53f4ba6464844ffd4f46021491a33f44dd7d2e26 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sun, 17 Mar 2019 19:48:47 +0100 Subject: [PATCH] Fix crystal dragon ability to match H3 --- config/creatures/neutral.json | 5 +---- lib/HeroBonus.h | 1 + server/CGameHandler.cpp | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/config/creatures/neutral.json b/config/creatures/neutral.json index f04512726..ba7c5136d 100644 --- a/config/creatures/neutral.json +++ b/config/creatures/neutral.json @@ -122,10 +122,7 @@ }, "crystals" : { - "type" : "GENERATE_RESOURCE", - "subtype" : "resource.crystal", - "val" : 1, - "propagator" : "HERO" + "type" : "SPECIAL_CRYSTAL_GENERATION" }, "FLYING_ARMY" : null }, diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 3d8e79ec9..3d8256e4d 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -269,6 +269,7 @@ public: BONUS_NAME(SHOOTS_ALL_ADJACENT) /* H4 Cyclops-like shoot (attacks all hexes neighboring with target) without spell-like mechanics */\ BONUS_NAME(BLOCK_MAGIC_BELOW) /*blocks casting spells of the level < value */ \ BONUS_NAME(DESTRUCTION) /*kills extra units after hit, subtype = 0 - kill percentage of units, 1 - kill amount, val = chance in percent to trigger, additional info - amount/percentage to kill*/ \ + BONUS_NAME(SPECIAL_CRYSTAL_GENERATION) /*crystal dragon crystal generation*/ \ /* end of list */ diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 257c22bb9..fc3675aca 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1739,6 +1739,38 @@ void CGameHandler::newTurn() n.res[elem.first] = elem.second.resources; + if(!firstTurn && newWeek) //weekly crystal generation if 1 or more crystal dragons in any hero army or town garrison + { + bool hasCrystalGenCreature = false; + for(CGHeroInstance * hero : elem.second.heroes) + { + for(auto stack : hero->stacks) + { + if(stack.second->hasBonusOfType(Bonus::SPECIAL_CRYSTAL_GENERATION)) + { + hasCrystalGenCreature = true; + break; + } + } + } + if(!hasCrystalGenCreature) //not found in armies, check towns + { + for(CGTownInstance * town : elem.second.towns) + { + for(auto stack : town->stacks) + { + if(stack.second->hasBonusOfType(Bonus::SPECIAL_CRYSTAL_GENERATION)) + { + hasCrystalGenCreature = true; + break; + } + } + } + } + if(hasCrystalGenCreature) + n.res[elem.first][Res::CRYSTAL] += 3; + } + for (CGHeroInstance *h : (elem).second.heroes) { if (h->visitedTown)