瀏覽代碼

* fixes for previous commit

mateuszb 16 年之前
父節點
當前提交
dce07fe1c9
共有 4 個文件被更改,包括 103 次插入6 次删除
  1. 85 2
      hch/CObjectHandler.cpp
  2. 16 2
      hch/CObjectHandler.h
  3. 1 1
      lib/RegisterTypes.cpp
  4. 1 1
      lib/map.cpp

+ 85 - 2
hch/CObjectHandler.cpp

@@ -1508,7 +1508,10 @@ CGTownInstance::CGTownInstance()
 }
 }
 
 
 CGTownInstance::~CGTownInstance()
 CGTownInstance::~CGTownInstance()
-{}
+{
+	for (std::vector<CGTownBuilding*>::const_iterator i = bonusingBuildings.begin(); i != bonusingBuildings.end(); i++) 
+		delete *i;
+}
 
 
 int CGTownInstance::spellsAtLevel(int level, bool checkGuild) const
 int CGTownInstance::spellsAtLevel(int level, bool checkGuild) const
 {
 {
@@ -1549,6 +1552,7 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
 		}
 		}
 		else
 		else
 		{
 		{
+			removeCapitols (h->getOwner(), true);
 			cb->setOwner(id, h->tempOwner);
 			cb->setOwner(id, h->tempOwner);
 		}
 		}
 	}
 	}
@@ -1583,6 +1587,7 @@ void CGTownInstance::initObj()
 				bonusingBuildings.push_back (new CTownBonus(17, this));
 				bonusingBuildings.push_back (new CTownBonus(17, this));
 			break;
 			break;
 	}
 	}
+	removeCapitols (getOwner(), false); // destroy other capitols
 }
 }
 
 
 int3 CGTownInstance::getSightCenter() const
 int3 CGTownInstance::getSightCenter() const
@@ -1599,10 +1604,37 @@ void CGTownInstance::fightOver( const CGHeroInstance *h, BattleResult *result )
 {
 {
 	if(result->winner == 0)
 	if(result->winner == 0)
 	{
 	{
-		cb->setOwner(id, h->tempOwner);
+		removeCapitols (h->getOwner(), true);
+		cb->setOwner (id, h->tempOwner); //give control after checkout is done
 	}
 	}
 }
 }
 
 
+void CGTownInstance::removeCapitols (ui8 owner, bool me) const
+{ 
+	if (hasCapitol()) // search for older capitol
+	{ 
+		PlayerState* state = cb->gameState()->getPlayer (owner); 
+		for (std::vector<CGTownInstance*>::const_iterator i = state->towns.begin(); i < state->towns.end(); ++i) 
+		{ 
+			if (*i != this && (*i)->hasCapitol()) 
+			{ 
+				if (me) 
+				{ 
+					RazeStructures rs; 
+					rs.tid = id; 
+					rs.bid.insert(13); 
+					si16 builded = destroyed;  
+					cb->sendAndApply(&rs); 
+					//cb->gameState()->getTown(id)->builtBuildings.erase(13); //destroy local capitol 
+					return; 
+				} 
+				else 
+					(*i)->builtBuildings.erase(13); //destroy all other capitols at the beginning of game 
+			} 
+		} 
+	} 
+} 
+
 void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
 void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
 {
 {
 	if(visitors.find(h->id)==visitors.end())
 	if(visitors.find(h->id)==visitors.end())
@@ -3099,6 +3131,38 @@ void CGBonusingObject::initObj()
 	}
 	}
 }
 }
 
 
+void CGMagicSpring::onHeroVisit(const CGHeroInstance * h) const 
+{ 
+	int messageID; 
+	InfoWindow iw; 
+	iw.player = h->tempOwner; 
+	iw.soundID = soundBase::GENIE; 
+	if (!visited) 
+	{ 
+		if (h->mana > h->manaLimit())  
+			messageID = 76; 
+		else 
+		{ 
+			messageID = 74; 
+			cb->setManaPoints (h->id, 2 * h->manaLimit()); 
+			cb->setObjProperty (id, 5, true); 
+		} 
+	} 
+	else 
+		messageID = 75; 
+	iw.text << std::pair<ui8,ui32>(11,messageID); 
+	cb->showInfoDialog(&iw); 
+} 
+const std::string & CGMagicSpring::getHoverText() const 
+{ 
+	hoverName = VLC->generaltexth->names[ID];
+	if(!visited)
+		hoverName += " " + VLC->generaltexth->allTexts[353]; //not visited
+	else
+		hoverName += " " + VLC->generaltexth->allTexts[352]; //visited
+	return hoverName;
+} 
+
 void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const
 void CGMagicWell::onHeroVisit( const CGHeroInstance * h ) const
 {
 {
 	int message;
 	int message;
@@ -4557,6 +4621,25 @@ void CCartographer::buyMap (const CGHeroInstance *h, ui32 accept) const
 	}
 	}
 }
 }
 
 
+void CShop::newTurn() const 
+{ 
+	switch (ID)
+	{
+		case 7: //ArtMerchant aka. Black Market
+			if (cb->getDate(0)%28 == 1)
+			{
+				cb->setObjProperty (id, 13, 0);
+				cb->setObjProperty (id, 14, rand());
+			}
+			break;
+		case 78: //Refugee Camp
+		case 95: //Tavern
+			if (cb->getDate(0)%7 == 1)
+				cb->setObjProperty (id, 14, rand());
+			break;
+	}
+}
+
 void CShop::setPropertyDer (ui8 what, ui32 val)
 void CShop::setPropertyDer (ui8 what, ui32 val)
 {
 {
 	switch (what)
 	switch (what)

+ 16 - 2
hch/CObjectHandler.h

@@ -441,6 +441,7 @@ public:
 	bool hasCapitol() const;
 	bool hasCapitol() const;
 	int dailyIncome() const; //calculates daily income of this town
 	int dailyIncome() const; //calculates daily income of this town
 	int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
 	int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
+	void removeCapitols (ui8 owner, bool me) const;
 
 
 	CGTownInstance();
 	CGTownInstance();
 	virtual ~CGTownInstance();
 	virtual ~CGTownInstance();
@@ -751,6 +752,19 @@ public:
 	}
 	}
 };
 };
 
 
+class DLL_EXPORT CGMagicSpring : public CGVisitableOPW 
+{///unfortunatelly, this one is quite different than others 
+public: 
+	void onHeroVisit(const CGHeroInstance * h) const; 
+	const std::string & getHoverText() const; 
+
+	template <typename Handler> void serialize(Handler &h, const int version) 
+	{ 
+		h & static_cast<CGObjectInstance&>(*this); 
+		h & visited; 
+	} 
+}; 
+
 class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
 class DLL_EXPORT CGMagicWell : public CGObjectInstance //objects giving bonuses to luck/morale/movement
 {
 {
 public:
 public:
@@ -948,8 +962,8 @@ public:
 
 
 	void initObj() {};
 	void initObj() {};
 	void setPropertyDer (ui8 what, ui32 val);
 	void setPropertyDer (ui8 what, ui32 val);
-	void newTurn() const {};
-	virtual void reset (ui32 val) {};
+	void newTurn() const;
+	virtual void reset (ui32 val) {}; //get new items for Black Market, Tavern, Refugee Camp 
 	void onHeroVisit (const CGHeroInstance * h) const {};
 	void onHeroVisit (const CGHeroInstance * h) const {};
 	virtual void trade (const CGHeroInstance * h) const {};
 	virtual void trade (const CGHeroInstance * h) const {};
 	
 	

+ 1 - 1
lib/RegisterTypes.cpp

@@ -42,7 +42,7 @@ void registerTypes1(Serializer &s)
 	s.template registerType<CGShrine>();
 	s.template registerType<CGShrine>();
 	s.template registerType<CGQuestGuard>();
 	s.template registerType<CGQuestGuard>();
 	s.template registerType<CGBonusingObject>();
 	s.template registerType<CGBonusingObject>();
-	//s.template registerType<CGMagicSpring>();
+	s.template registerType<CGMagicSpring>();
 	s.template registerType<CGMagicWell>();
 	s.template registerType<CGMagicWell>();
 	s.template registerType<CGObservatory>();
 	s.template registerType<CGObservatory>();
 	s.template registerType<CGKeys>();
 	s.template registerType<CGKeys>();

+ 1 - 1
lib/map.cpp

@@ -1950,7 +1950,7 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
 			}
 			}
 		case 48: //Magic Spring
 		case 48: //Magic Spring
 			{
 			{
-				//nobj = new CGMagicSpring();
+				nobj = new CGMagicSpring();
 				break;
 				break;
 			}
 			}
 		default:
 		default: