Browse Source

Partial garrison support, battles are played out and the object gets flagged.

OnionKnight 16 years ago
parent
commit
5f2d6b5e4c
2 changed files with 24 additions and 0 deletions
  1. 21 0
      hch/CObjectHandler.cpp
  2. 3 0
      hch/CObjectHandler.h

+ 21 - 0
hch/CObjectHandler.cpp

@@ -3497,6 +3497,27 @@ void CGScholar::initObj()
 	}
 }
 
+void CGGarrison::onHeroVisit (const CGHeroInstance *h) const
+{
+	if (h->tempOwner != tempOwner && army) {
+		//TODO: Find a way to apply magic garrison effects in battle.
+		cb->startBattleI(h, this, false, boost::bind(&CGGarrison::fightOver, this, h, _1));
+		return;
+	}
+
+	//New owner.
+	if (h->tempOwner != tempOwner)
+		cb->setOwner(id, h->tempOwner);
+
+	//TODO: Garrison visit screen.
+}
+
+void CGGarrison::fightOver (const CGHeroInstance *h, BattleResult *result) const
+{
+	if (result->winner == 0)
+		onHeroVisit(h);
+}
+
 void CGOnceVisitable::onHeroVisit( const CGHeroInstance * h ) const
 {
 	int sound = 0;

+ 3 - 0
hch/CObjectHandler.h

@@ -602,6 +602,9 @@ class DLL_EXPORT CGGarrison : public CArmedInstance
 public:
 	ui8 removableUnits;
 
+	void onHeroVisit (const CGHeroInstance *h) const;
+	void fightOver (const CGHeroInstance *h, BattleResult *result) const;
+
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
 		h & static_cast<CArmedInstance&>(*this);