瀏覽代碼

* first part of siege support
* minor fix

mateuszb 16 年之前
父節點
當前提交
2c7d7f4094
共有 5 個文件被更改,包括 60 次插入5 次删除
  1. 9 1
      CCallback.cpp
  2. 2 0
      CCallback.h
  3. 35 3
      client/CBattleInterface.cpp
  4. 13 0
      client/CBattleInterface.h
  5. 1 1
      lib/CGameState.h

+ 9 - 1
CCallback.cpp

@@ -596,11 +596,19 @@ bool CCallback::battleCanCastSpell()
 		return gs->curB->castSpells[1] == 0 && gs->getHero(gs->curB->hero2)->getArt(17);
 }
 
-bool CCallback:: battleCanFlee()
+bool CCallback::battleCanFlee()
 {
 	return gs->battleCanFlee(player);
 }
 
+const CGTownInstance *CCallback::battleGetDefendedTown()
+{
+	if(!gs->curB || gs->curB->tid == -1)
+		return NULL;
+
+	return gs->map->towns[gs->curB->tid];
+}
+
 void CCallback::swapGarrisonHero( const CGTownInstance *town )
 {
 	if(town->tempOwner != player) return;

+ 2 - 0
CCallback.h

@@ -174,6 +174,7 @@ public:
 	virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest
 	virtual bool battleCanCastSpell()=0; //returns true, if caller can cast a spell
 	virtual bool battleCanFlee()=0; //returns true if caller can flee from the battle
+	virtual const CGTownInstance * battleGetDefendedTown()=0; //returns defended town if current battle is a siege, NULL instead
 };
 
 struct HeroMoveDetails
@@ -275,6 +276,7 @@ public:
 	bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
 	bool battleCanCastSpell(); //returns true, if caller can cast a spell
 	bool battleCanFlee(); //returns true if caller can flee from the battle
+	const CGTownInstance * battleGetDefendedTown(); //returns defended town if current battle is a siege, NULL instead
 
 //XXX hmmm _tmain on _GNUC_ wtf?
 //friends

+ 35 - 3
client/CBattleInterface.cpp

@@ -23,6 +23,7 @@
 #include "../lib/NetPacks.h"
 #include "CPlayerInterface.h"
 #include "../hch/CVideoHandler.h"
+#include "../hch/CTownHandler.h"
 #include <boost/assign/list_of.hpp>
 #ifndef __GNUC__
 const double M_PI = 3.14159265358979323846;
@@ -75,7 +76,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	: attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0), activeStack(-1), 
 	  mouseHoveredStack(-1), previouslyHoveredHex(-1), currentlyHoveredHex(-1), spellDestSelectMode(false),
 	  spellToCast(NULL), attackingInfo(NULL), givenCommand(NULL), myTurn(false), resWindow(NULL), 
-	  showStackQueue(false), moveStarted(false), moveSh(-1)
+	  showStackQueue(false), moveStarted(false), moveSh(-1), siegeH(NULL)
 {
 	pos = myRect;
 	strongInterest = true;
@@ -88,9 +89,27 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C
 	{
 		newStack(b->second.ID);
 	}
+
+	
+	//preparing siege info
+	const CGTownInstance * town = LOCPLINT->cb->battleGetDefendedTown();
+	if(town)
+	{
+		siegeH = new SiegeHelper(town);
+	}
+
 	//preparing menu background and terrain
-	std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
-	background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
+	if(siegeH)
+	{
+		background = BitmapHandler::loadBitmap( siegeH->getBackgroundName() );
+	}
+	else
+	{
+		std::vector< std::string > & backref = graphics->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ];
+		background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] );
+	}
+	
+	//preparign menu background
 	menu = BitmapHandler::loadBitmap("CBAR.BMP");
 	graphics->blueToPlayersAdv(menu, hero1->tempOwner);
 
@@ -277,6 +296,7 @@ CBattleInterface::~CBattleInterface()
 	for(std::map< int, CDefHandler * >::iterator g=idToObstacle.begin(); g!=idToObstacle.end(); ++g)
 		delete g->second;
 
+	delete siegeH;
 	LOCPLINT->battleInt = NULL;
 }
 
@@ -3146,3 +3166,15 @@ void CBattleOptionsWindow::bExitf()
 {
 	GH.popIntTotally(this);
 }
+
+std::string CBattleInterface::SiegeHelper::townTypeInfixes[F_NUMBER] = {"CS", "RM", "TW", "IN", "NC", "DN", "ST", "FR" "EL"};
+
+CBattleInterface::SiegeHelper::SiegeHelper(const CGTownInstance *siegeTown)
+: town(siegeTown)
+{
+}
+
+std::string CBattleInterface::SiegeHelper::getBackgroundName() const
+{
+	return "SG" + townTypeInfixes[town->town->typeID] + "BACK.BMP";
+}

+ 13 - 0
client/CBattleInterface.h

@@ -28,6 +28,7 @@ struct SpellCast;
 template <typename T> struct CondSh;
 struct SetStackEffect;;
 struct BattleAction;
+class CGTownInstance;
 
 class CBattleInterface;
 
@@ -225,6 +226,18 @@ private:
 		CDefHandler * anim; //animation to display
 	};
 	std::list<SBattleEffect> battleEffects; //different animations to display on the screen like spell effects
+
+	class SiegeHelper
+	{
+	private:
+		static std::string townTypeInfixes[F_NUMBER]; //for internal use only - to build filenames
+	public:
+		const CGTownInstance * town; //besieged town
+		SiegeHelper(const CGTownInstance * siegeTown); //c-tor
+
+		//filename getters
+		std::string getBackgroundName() const;
+	} * siegeH;
 public:
 	CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect); //c-tor
 	~CBattleInterface(); //d-tor

+ 1 - 1
lib/CGameState.h

@@ -120,7 +120,7 @@ struct DLL_EXPORT BattleInfo
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & side1 & side2 & round & activeStack & siege & tile & stacks & army1 & army2 & hero1 & hero2 & obstacles
+		h & side1 & side2 & round & activeStack & siege & tid & tile & stacks & army1 & army2 & hero1 & hero2 & obstacles
 			& castSpells;
 	}
 	CStack * getNextStack(); //which stack will have turn after current one