From fd66234a3992fa037fffa0250babc354b02a4e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Fri, 20 Feb 2009 12:39:27 +0000 Subject: [PATCH] * Witch HutL After the first visit to the hut, right-click/hover on that hut mention the skill available. * refactorings --- CAdvmapInterface.cpp | 3 ++- CGameState.cpp | 33 ++++------------------- CGameState.h | 1 - hch/CObjectHandler.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++ hch/CObjectHandler.h | 13 +++++++-- 5 files changed, 79 insertions(+), 32 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index 61fa1008a..432045a78 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -497,7 +497,8 @@ void CTerrainRect::mouseMoved (const SDL_MouseMotionEvent & sEvent) std::vector temp = LOCPLINT->cb->getObjDescriptions(pom); if (temp.size()) { - LOCPLINT->adventureInt->statusbar.print((*((temp.end())-1))); + boost::replace_all(temp.back(),"\n"," "); + LOCPLINT->adventureInt->statusbar.print(temp.back()); } else { diff --git a/CGameState.cpp b/CGameState.cpp index bd7ad4dc9..1c8026387 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -852,7 +852,11 @@ void CGameState::applyNL(IPack * pack) case 1001://set object property { SetObjectProperty *p = static_cast(pack); - setObjProperty(p); + CGObjectInstance *obj = map->objects[p->id]; + if(!obj) + tlog1 << "Wrong object ID - property cannot be set!\n"; + else + obj->setProperty(p->what,p->val); break; } case 1002: @@ -1789,33 +1793,6 @@ void CGameState::loadTownDInfos() } } -void CGameState::setObjProperty( SetObjectProperty * p ) -{ - CGObjectInstance *obj = map->objects[p->id]; - - switch(p->what) - { - case 1: - obj->tempOwner = p->val; - break; - case 2: - obj->blockVisit = p->val; - break; - case 3: - static_cast(obj)->army.slots[0].second = p->val; - break; - case 4: - static_cast(obj)->visitors.insert(p->val); - break; - case 5: - static_cast(obj)->visited = p->val; - break; - case 6: - obj->ID = p->val; - break; - } -} - void CGameState::getNeighbours(int3 tile, std::vector &vec, bool onLand) { vec.clear(); diff --git a/CGameState.h b/CGameState.h index 33bc18bc7..d358140bb 100644 --- a/CGameState.h +++ b/CGameState.h @@ -228,7 +228,6 @@ private: void loadTownDInfos(); void applyNL(IPack * pack); - void setObjProperty( SetObjectProperty * p ); void apply(IPack * pack); void randomizeObject(CGObjectInstance *cur); std::pair pickObject(CGObjectInstance *obj); diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 20cf401a6..9d2a11f24 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -45,6 +45,9 @@ IObjectInterface::IObjectInterface() void IObjectInterface::initObj() {} +void IObjectInterface::setProperty( ui8 what, ui32 val ) +{} + void CObjectHandler::loadObjects() { tlog5 << "\t\tReading cregens \n"; @@ -181,6 +184,26 @@ void CGObjectInstance::initObj() { } +void CGObjectInstance::setProperty( ui8 what, ui32 val ) +{ + switch(what) + { + case 1: + tempOwner = val; + break; + case 2: + blockVisit = val; + break; + case 6: + ID = val; + break; + } + setPropertyDer(what, val); +} + +void CGObjectInstance::setPropertyDer( ui8 what, ui32 val ) +{} + int lowestSpeed(const CGHeroInstance * chi) { if(!chi->army.slots.size()) @@ -700,6 +723,11 @@ const HeroBonus * CGHeroInstance::getBonus( int from, int id ) const return NULL; } +void CGHeroInstance::setPropertyDer( ui8 what, ui32 val ) +{ + if(what == 3) + army.slots[0].second = val; +} int CGTownInstance::getSightDistance() const //returns sight distance { return 10; @@ -1084,6 +1112,12 @@ void CGVisitableOPH::arenaSelected( int heroID, int primSkill ) const cb->changePrimSkill(heroID,primSkill,2); } +void CGVisitableOPH::setPropertyDer( ui8 what, ui32 val ) +{ + if(what == 4) + visitors.insert(val); +} + bool CArmedInstance::needsLastStack() const { return false; @@ -1342,6 +1376,12 @@ void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const } } +void CGVisitableOPW::setPropertyDer( ui8 what, ui32 val ) +{ + if(what == 5) + visited = val; +} + void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const { int destinationid=-1; @@ -1566,6 +1606,8 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const { InfoWindow iw; iw.player = h->getOwner(); + if(!vstd::contains(playersVisited,h->tempOwner)) + cb->setObjProperty(id,10,h->tempOwner); if(h->getSecSkillLevel(ability)) //you alredy know this skill { @@ -1588,6 +1630,25 @@ void CGWitchHut::onHeroVisit( const CGHeroInstance * h ) const cb->showInfoDialog(&iw); } +const std::string & CGWitchHut::getHoverText() const +{ + hoverName = VLC->generaltexth->names[ID]; + if(vstd::contains(playersVisited,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]); + if(cb->getSelectedHero(cb->getCurrentPlayer())->getSecSkillLevel(ability)) //hero knows that ability + hoverName += "\n\n" + VLC->generaltexth->allTexts[357]; // (Already learned) + } + return hoverName; +} + +void CGWitchHut::setPropertyDer( ui8 what, ui32 val ) +{ + if(what == 10) + playersVisited.insert(val); +} + void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const { diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 4cfb4780e..8a982f4a9 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -88,7 +88,8 @@ public: virtual void onHeroVisit(const CGHeroInstance * h) const; virtual void onHeroLeave(const CGHeroInstance * h) const; virtual void newTurn() const; - virtual void initObj(); + virtual void initObj(); //synchr + virtual void setProperty(ui8 what, ui32 val);//synchr }; class DLL_EXPORT CGObjectInstance : protected IObjectInterface @@ -120,6 +121,8 @@ public: virtual const std::string & getHoverText() const; ////////////////////////////////////////////////////////////////////////// void initObj(); + void setProperty(ui8 what, ui32 val);//synchr + virtual void setPropertyDer(ui8 what, ui32 val);//synchr friend class CGameHandler; @@ -239,6 +242,8 @@ public: virtual ~CGHeroInstance(); ////////////////////////////////////////////////////////////////////////// + + void setPropertyDer(ui8 what, ui32 val);//synchr void initObj(); void onHeroVisit(const CGHeroInstance * h) const; }; @@ -321,6 +326,7 @@ public: si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems const std::string & getHoverText() const; + void setPropertyDer(ui8 what, ui32 val);//synchr void onHeroVisit(const CGHeroInstance * h) const; void onNAHeroVisit(int heroID, bool alreadyVisited) const; void initObj(); @@ -422,9 +428,11 @@ class DLL_EXPORT CGWitchHut : public CGObjectInstance { 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) @@ -580,6 +588,7 @@ class DLL_EXPORT CGVisitableOPW : public CGObjectInstance //objects visitable OP public: ui8 visited; //true if object has been visited this week + void setPropertyDer(ui8 what, ui32 val);//synchr void onHeroVisit(const CGHeroInstance * h) const; void newTurn() const;