diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 03406deda..97dacaf4e 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -48,6 +48,17 @@ void IObjectInterface::initObj() void IObjectInterface::setProperty( ui8 what, ui32 val ) {} +void CPlayersVisited::setPropertyDer( ui8 what, ui32 val ) +{ + if(what == 10) + players.insert(val); +} + +bool CPlayersVisited::hasVisited( ui8 player ) const +{ + return vstd::contains(players,player); +} + void CObjectHandler::loadObjects() { tlog5 << "\t\tReading cregens \n"; @@ -1641,7 +1652,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const { InfoWindow iw; iw.player = h->getOwner(); - if(!vstd::contains(playersVisited,h->tempOwner)) + if(!hasVisited(h->tempOwner)) cb->setObjProperty(id,10,h->tempOwner); if(h->getSecSkillLevel(ability)) //you alredy know this skill @@ -1668,7 +1679,7 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const const std::string & CGWitchHut::getHoverText() const { hoverName = VLC->generaltexth->names[ID]; - if(vstd::contains(playersVisited,cb->getCurrentPlayer())) //TODO: use local player, not current + if(hasVisited(cb->getCurrentPlayer())) //TODO: use local player, not current { hoverName += "\n" + VLC->generaltexth->allTexts[356]; // + (learn %s) boost::algorithm::replace_first(hoverName,"%s",VLC->generaltexth->skillName[ability]); @@ -1678,11 +1689,6 @@ const std::string & CGWitchHut::getHoverText() const return hoverName; } -void CGWitchHut::setPropertyDer( ui8 what, ui32 val ) -{ - if(what == 10) - playersVisited.insert(val); -} void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const { @@ -1917,6 +1923,9 @@ void CGShrine::onHeroVisit( const CGHeroInstance * h ) const return; } + if(!hasVisited(h->tempOwner)) + cb->setObjProperty(id,10,h->tempOwner); + InfoWindow iw; iw.player = h->getOwner(); iw.text.addTxt(MetaString::ADVOB_TXT,127 + ID - 88); @@ -1976,5 +1985,14 @@ void CGShrine::initObj() const std::string & CGShrine::getHoverText() const { + hoverName = VLC->generaltexth->names[ID]; + if(hasVisited(cb->getCurrentPlayer())) //TODO: use local player, not current + { + hoverName += "\n" + VLC->generaltexth->allTexts[355]; // + (learn %s) + boost::algorithm::replace_first(hoverName,"%s",VLC->spellh->spells[spell].name); + const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer()); + if(h && vstd::contains(h->spells,spell)) //hero knows that ability + hoverName += "\n\n" + VLC->generaltexth->allTexts[354]; // (Already learned) + } return hoverName; -} \ No newline at end of file +} diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 7ee08ae2a..46607e9b9 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -136,6 +136,20 @@ public: } }; +class DLL_EXPORT CPlayersVisited: public CGObjectInstance +{ +public: + std::set players; + + bool hasVisited(ui8 player) const; + void setPropertyDer(ui8 what, ui32 val);//synchr + + template void serialize(Handler &h, const int version) + { + h & players; + } +}; + class DLL_EXPORT CArmedInstance: public CGObjectInstance { public: @@ -432,20 +446,18 @@ public: } }; -class DLL_EXPORT CGWitchHut : public CGObjectInstance +class DLL_EXPORT CGWitchHut : public CPlayersVisited { public: std::vector allowedAbilities; ui32 ability; - std::set playersVisited; //players who know what skill is given here (used for hover texts) - void setPropertyDer(ui8 what, ui32 val);//synchr const std::string & getHoverText() const; void onHeroVisit(const CGHeroInstance * h) const; void initObj(); template void serialize(Handler &h, const int version) { - h & static_cast(*this); + h & static_cast(*this) & static_cast(*this);; h & allowedAbilities & ability; } }; @@ -532,7 +544,7 @@ public: } }; -class DLL_EXPORT CGShrine : public CGObjectInstance +class DLL_EXPORT CGShrine : public CPlayersVisited { public: ui8 spell; //number of spell or 255 if random @@ -542,7 +554,7 @@ public: template void serialize(Handler &h, const int version) { - h & static_cast(*this); + h & static_cast(*this) & static_cast(*this);; h & spell; } }; diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index cf4ef4e9c..b935421a6 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -104,5 +104,6 @@ bool IGameCallback::isAllowed( int type, int id ) return gs->map->allowedSpell[id]; default: tlog1 << "Wrong call to IGameCallback::isAllowed!\n"; + return false; } } \ No newline at end of file