From 9792c64cbf2003919bb49c680ecad1d3aa17c92b Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Sun, 4 Oct 2009 14:20:19 +0000 Subject: [PATCH] Fixed bug #71. Little redesign of town buildings handling. --- hch/CObjectHandler.cpp | 3 +-- server/CGameHandler.cpp | 13 +++++++++++-- server/CGameHandler.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 1363ae3fb..2cd26801f 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1561,9 +1561,8 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const cb->setOwner(id, h->tempOwner); } } + cb->heroVisitCastle(id, h->id); - for (std::vector::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++) - (*i)->onHeroVisit (h); //put it inside heroVisitCastle call, make sure *visitingHero is set } void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 96297549b..cd8431c62 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -1624,7 +1624,15 @@ void CGameHandler::heroVisitCastle(int obj, int heroID) vc.tid = obj; vc.flags |= 1; sendAndApply(&vc); - giveSpells(getTown(obj),getHero(heroID)); + vistiCastleObjects (getTown(obj), getHero(heroID)); + giveSpells (getTown(obj), getHero(heroID)); +} + +void CGameHandler::vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h) +{ + std::vector::const_iterator i; + for (i = t->bonusingBuildings.begin(); i != t->bonusingBuildings.end(); i++) + (*i)->onHeroVisit (h); } void CGameHandler::stopHeroVisitCastle(int obj, int heroID) @@ -2414,7 +2422,8 @@ bool CGameHandler::hireHero( ui32 tid, ui8 hid ) sr.val = gs->getPlayer(t->tempOwner)->resources[6] - 2500; sendAndApply(&sr); - giveSpells(t,nh); + vistiCastleObjects (t, nh); + giveSpells (t,nh); return true; } diff --git a/server/CGameHandler.h b/server/CGameHandler.h index a59c4a0ba..d96d06036 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -123,6 +123,7 @@ public: void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures); void showCompInfo(ShowInInfobox * comp); void heroVisitCastle(int obj, int heroID); + void vistiCastleObjects (const CGTownInstance *t, const CGHeroInstance *h); void stopHeroVisitCastle(int obj, int heroID); void giveHeroArtifact(int artid, int hid, int position); //pos==-1 - first free slot in backpack; pos==-2 - default if available or backpack void moveArtifact(int hid, int oldPosition, int destPos);