Browse Source

Support for Castle Stables. These are compatible with advMap Stables.

DjWarmonger 16 years ago
parent
commit
2cf3e6885f
3 changed files with 70 additions and 2 deletions
  1. 54 2
      hch/CObjectHandler.cpp
  2. 15 0
      hch/CObjectHandler.h
  3. 1 0
      lib/RegisterTypes.cpp

+ 54 - 2
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<ui8,ui32>(11, 137);
+					cb->showInfoDialog(&iw);
+				}
+				break;
+		}
+	}
+}
 CTownBonus::CTownBonus (int index, CGTownInstance *TOWN)
 {
 	ID = index;

+ 15 - 0
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<si32> visitors;
+	void setProperty(ui8 what, ui32 val);
+	void onHeroVisit (const CGHeroInstance * h) const;
+
+	COPWBonus (int index, CGTownInstance *TOWN);
+	COPWBonus (){ID = 0; town = NULL;};
+	template <typename Handler> void serialize(Handler &h, const int version)
+	{
+		h & static_cast<CGTownBuilding&>(*this);
+		h & visitors;
+	}
+};
 class DLL_EXPORT CTownBonus : public CGTownBuilding
 {
 ///used for one-time bonusing structures

+ 1 - 0
lib/RegisterTypes.cpp

@@ -23,6 +23,7 @@ void registerTypes1(Serializer &s)
 	s.template registerType<CGHeroInstance>();
 	s.template registerType<CGTownInstance>();
 	s.template registerType<CTownBonus>();
+	s.template registerType<COPWBonus>();
 	s.template registerType<CGPandoraBox>();
 	s.template registerType<CGEvent>();
 	s.template registerType<CGDwelling>();