diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index df6a94136..0facaa8e2 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -1584,11 +1584,16 @@ void CGTownInstance::initObj() } switch (subID) { //add new visitable objects + case 0: + bonusingBuildings.push_back (new COPWBonus(21, this)); //Stables + break; case 2: case 3: case 5: case 6: - bonusingBuildings.push_back (new CTownBonus(23, this)); + bonusingBuildings.push_back (new CTownBonus(23, this)); + if (subID == 5) + bonusingBuildings.push_back (new COPWBonus(18, this)); //Vortex break; case 7: - bonusingBuildings.push_back (new CTownBonus(17, this)); + bonusingBuildings.push_back (new CTownBonus(17, this)); break; } if (getOwner() != 255) @@ -1965,6 +1970,53 @@ void CGVisitableOPH::schoolSelected(int heroID, ui32 which) const cb->changePrimSkill(heroID, base + which-1, +1); //give appropriate skill } +COPWBonus::COPWBonus (int index, CGTownInstance *TOWN) +{ + ID = index; + town = TOWN; + id = town->bonusingBuildings.size(); +} +void COPWBonus::setProperty(ui8 what, ui32 val) +{ + switch (what) + { + case 4: + visitors.insert(val); + break; + case 11: + visitors.clear(); + break; + } +} +void COPWBonus::onHeroVisit (const CGHeroInstance * h) const +{ + int heroID = h->id; + if (town->builtBuildings.find(ID) != town->builtBuildings.end()) + { + InfoWindow iw; + iw.player = h->tempOwner; + switch (ID) + { + case 18: //Mana Vortex + if (visitors.size()) + { + cb->setObjProperty (town->id, 11, id); //add to visitors + } + break; + case 21: //Stables + if (!h->getBonus(HeroBonus::OBJECT, 94)) //no advMap Stables + { + GiveBonus gb; + gb.bonus = HeroBonus(HeroBonus::ONE_WEEK, HeroBonus::LAND_MOVEMENT, HeroBonus::OBJECT, 600, 94, VLC->generaltexth->arraytxt[100]); + gb.hid = heroID; + cb->giveHeroBonus(&gb); + iw.text << std::pair(11, 137); + cb->showInfoDialog(&iw); + } + break; + } + } +} CTownBonus::CTownBonus (int index, CGTownInstance *TOWN) { ID = index; diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index d84506b09..0f065b633 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -371,6 +371,21 @@ public: h & ID & id; } }; +class DLL_EXPORT COPWBonus : public CGTownBuilding +{///used for OPW bonusing structures +public: + std::set visitors; + void setProperty(ui8 what, ui32 val); + void onHeroVisit (const CGHeroInstance * h) const; + + COPWBonus (int index, CGTownInstance *TOWN); + COPWBonus (){ID = 0; town = NULL;}; + template void serialize(Handler &h, const int version) + { + h & static_cast(*this); + h & visitors; + } +}; class DLL_EXPORT CTownBonus : public CGTownBuilding { ///used for one-time bonusing structures diff --git a/lib/RegisterTypes.cpp b/lib/RegisterTypes.cpp index d2fd77aec..a38b68a3f 100644 --- a/lib/RegisterTypes.cpp +++ b/lib/RegisterTypes.cpp @@ -23,6 +23,7 @@ void registerTypes1(Serializer &s) s.template registerType(); s.template registerType(); s.template registerType(); + s.template registerType(); s.template registerType(); s.template registerType(); s.template registerType();