From 38fd05f65585097f666602fc027a020bf290081a Mon Sep 17 00:00:00 2001 From: Dmitry Orlov Date: Mon, 28 Sep 2020 01:32:33 +0300 Subject: [PATCH] Minor fix: apply Monday bonuses to heroes who have slept overnight --- client/Client.h | 1 + lib/IGameCallback.h | 1 + lib/mapObjects/CGTownInstance.cpp | 14 ++++++++++++-- server/CGameHandler.cpp | 12 ++++++------ server/CGameHandler.h | 2 +- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/client/Client.h b/client/Client.h index 6e0cabf00..ccd822009 100644 --- a/client/Client.h +++ b/client/Client.h @@ -194,6 +194,7 @@ public: void showCompInfo(ShowInInfobox * comp) override {}; void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) override {}; + void visitCastleObjects(const CGTownInstance * obj, const CGHeroInstance * hero) override {}; void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero) override {}; void startBattlePrimary(const CArmedInstance * army1, const CArmedInstance * army2, int3 tile, const CGHeroInstance * hero1, const CGHeroInstance * hero2, bool creatureBank = false, const CGTownInstance * town = nullptr) override {}; //use hero=nullptr for no hero void startBattleI(const CArmedInstance * army1, const CArmedInstance * army2, int3 tile, bool creatureBank = false) override {}; //if any of armies is hero, hero will be used diff --git a/lib/IGameCallback.h b/lib/IGameCallback.h index dda1da39b..40f6f0c4e 100644 --- a/lib/IGameCallback.h +++ b/lib/IGameCallback.h @@ -80,6 +80,7 @@ public: virtual void showCompInfo(ShowInInfobox * comp)=0; virtual void heroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0; + virtual void visitCastleObjects(const CGTownInstance * obj, const CGHeroInstance * hero)=0; virtual void stopHeroVisitCastle(const CGTownInstance * obj, const CGHeroInstance * hero)=0; virtual void startBattlePrimary(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool creatureBank = false, const CGTownInstance *town = nullptr)=0; //use hero=nullptr for no hero virtual void startBattleI(const CArmedInstance *army1, const CArmedInstance *army2, int3 tile, bool creatureBank = false)=0; //if any of armies is hero, hero will be used diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 981d21286..d9ee3ad24 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -798,6 +798,14 @@ void CGTownInstance::newTurn(CRandomGenerator & rand) const cb->setObjProperty (id, ObjProperty::STRUCTURE_CLEAR_VISITORS, (elem)->id); //reset visitors for Mana Vortex } + //get Mana Vortex or Stables bonuses + //same code is in the CGameHandler::buildStructure method + if (visitingHero != nullptr) + cb->visitCastleObjects(this, visitingHero); + + if (garrisonHero != nullptr) + cb->visitCastleObjects(this, garrisonHero); + if (tempOwner == PlayerColor::NEUTRAL) //garrison growth for neutral towns { std::vector nativeCrits; //slots @@ -1536,13 +1544,15 @@ void COPWBonus::onHeroVisit (const CGHeroInstance * h) const } break; case ETownType::DUNGEON: //Mana Vortex - if (visitors.empty() && h->mana <= h->manaLimit() * 2) + if (visitors.empty()) { - cb->setManaPoints (heroID, 2 * h->manaLimit()); + if (h->mana < h->manaLimit() * 2) + cb->setManaPoints(heroID, 2 * h->manaLimit()); //TODO: investigate line below //cb->setObjProperty (town->id, ObjProperty::VISITED, true); iw.text << VLC->generaltexth->allTexts[579]; cb->showInfoDialog(&iw); + //extra visit penalty if hero alredy had double mana points (or even more?!) town->addHeroToStructureVisitors(h, id); } break; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 8cd46c11b..5408f96e2 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2508,13 +2508,13 @@ void CGameHandler::heroVisitCastle(const CGTownInstance * obj, const CGHeroInsta vc.tid = obj->id; vc.flags |= 1; sendAndApply(&vc); - vistiCastleObjects (obj, hero); - giveSpells (obj, hero); + visitCastleObjects(obj, hero); + giveSpells(obj, hero); checkVictoryLossConditionsForPlayer(hero->tempOwner); //transported artifact? } -void CGameHandler::vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h) +void CGameHandler::visitCastleObjects(const CGTownInstance * t, const CGHeroInstance * h) { std::vector::const_iterator i; for (i = t->bonusingBuildings.begin(); i != t->bonusingBuildings.end(); i++) @@ -3161,9 +3161,9 @@ bool CGameHandler::buildStructure(ObjectInstanceID tid, BuildingID requestedID, sendAndApply(&fw); if (t->visitingHero) - vistiCastleObjects (t, t->visitingHero); + visitCastleObjects(t, t->visitingHero); if (t->garrisonHero) - vistiCastleObjects (t, t->garrisonHero); + visitCastleObjects(t, t->garrisonHero); checkVictoryLossConditionsForPlayer(t->tempOwner); return true; @@ -3828,7 +3828,7 @@ bool CGameHandler::hireHero(const CGObjectInstance *obj, ui8 hid, PlayerColor pl if (t) { - vistiCastleObjects (t, nh); + visitCastleObjects(t, nh); giveSpells (t,nh); } return true; diff --git a/server/CGameHandler.h b/server/CGameHandler.h index d8ebc10ef..f7e9e92f0 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -181,7 +181,7 @@ public: void setPortalDwelling(const CGTownInstance * town, bool forced, bool clear); void visitObjectOnTile(const TerrainTile &t, const CGHeroInstance * h); bool teleportHero(ObjectInstanceID hid, ObjectInstanceID dstid, ui8 source, PlayerColor asker = PlayerColor::NEUTRAL); - void vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h); + void visitCastleObjects(const CGTownInstance * obj, const CGHeroInstance * hero); void levelUpHero(const CGHeroInstance * hero, SecondarySkill skill);//handle client respond and send one more request if needed void levelUpHero(const CGHeroInstance * hero);//initial call - check if hero have remaining levelups & handle them void levelUpCommander (const CCommanderInstance * c, int skill); //secondary skill 1 to 6, special skill : skill - 100